C#4.0: clearing up some doubts

Published Tue, Jun 16 2009 16:53

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

Filed under:

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover