Howto reflect object into an only at runtime known type?

Just use dynamic public static class DynamicCast { public static T Cast(object o) { return (T) (dynamic) o; } } This will automatically use any implicit/explicit operators that exist on the run-time type of o and/or the type T (Your code is incomplete because you’re searching only one of the two. ) The rest of your question is extremely unclear. You need to rephrase it.

The code is also unclear: what is the variable castedAssetType for? You are only assigning to it but then not using it.

Just use dynamic. Public static class DynamicCast { public static T Cast(object o) { return (T) (dynamic) o; } } This will automatically use any implicit/explicit operators that exist on the run-time type of o and/or the type T. (Your code is incomplete because you’re searching only one of the two.) The rest of your question is extremely unclear.

You need to rephrase it. The code is also unclear: what is the variable castedAssetType for? You are only assigning to it but then not using it.

Ehm, it doesn´t work. But please wait for some minutes. I´m trying something different... – Razer Apr 9 at 21:46 1 Could have been nice to mention that this requires C# 4.0 and the DLR – sehe Apr 9 at 22:37 @sehe: Should I also mention that this requires a compiler?

And that it requires a computer? Come on. – Timwi Apr 10 at 19:10 Well, not everyone has it, clearly the OP wasn't previously aware of it, AND you brisked him of for being extremely unclear?

I think it is fair to be a bit more forthcoming, or less demanding on the other hand. Gave you a +1 by the way, because it is obviously a good answer :) – sehe Apr 10 at 19:23.

I got the solution... I just had to add an generic method "Cast()" to AssetData. I just came on this idea, because now I know I can invoke a generic method ;) Here´s the solution: if (pinf.PropertyType. IsGenericType) { MethodInfo method = assetData.GetType().

GetMethod("Cast"). GetGenericMethodDefinition(). MakeGenericMethod( assetData.

AssetType); dynamic castedAsset = method. Invoke(assetData, null); pinf. SetValue(comp, castedAsset, null); } Sorry because of my unclear code.In future I will change this if I ask ;).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions