C#4.0: clearing up some doubts

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 :,,)


~ by Luis Abreu on June 16, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: