Ray's playground

 

Item 40: Use Dynamic for Parameters That Receive Anonymous Types(Effective C#)

You can leverage dynamic to create methods that are intended to be used with anonymous types. It’s a technique to be used sparingly, like strong spices. If you find yourself creating many methods using dynamic invocation that are intended for use with anonymous types, that’s a strong indication that you should create a concrete type to represent that concept. It will be much easier to maintain over time, and you’ll have better support from the compiler and the type system. However, when you need one or two utility methods that use an anonymous type, dynamic invocation is a simple way to create that behavior.

posted on 2011-02-26 10:38  Ray Z  阅读(193)  评论(0编辑  收藏  举报

导航