After my last post on C# 4.0, I’ve had an interesting exchange of tweets with Thomas Johansen about the usefulness of the code I’ve shown. As Thomas points out, knowing the type means that you should always cast it to that type so that you work with strongly typed verification (ie, compile time checking). In practice, what he’s saying is that example is completely useless because if you know the type of the object you’re creating, then you should always cast it to that type before using it.
I do agree with him and that’s why I’ve ended up writing this post so that there isn’t any doubt regarding what you should do: whenever possible, you should work with the type instead of relying in dynamic types or in reflection.
Since I’ve already published the code, what I’d really like is that you concentrate only in the dynamic usage parte and read the CreateInstance invocatio as GetMeADynamicObjectFromSomewhereWhichHasSeveralKnownProperties. Can you guys do that? thanks :,,)