Welcome to MSDN Blogs Sign in | Join | Help

New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

C# MVP and wunderkind Bill Wagner has written an article entitled Dynamic Method Bags which is now available on MSDN. Bill explores the new dynamic feature in C# 4.0. Most posts on this subject explain how to use dynamic to call Python, Ruby or Office. In his article, Bill explains how dynamic can be used not to call another language or tool, but to call your own C# objects without directly using the reflection API’s. The solution he provides combines generics, expression tress and dynamic to create a “type that allows developers to add new methods at runtime” and call those methods through dynamic dispatch.

Resources

kick it on DotNetKicks.com
Published Tuesday, November 03, 2009 2:30 PM by Charlie Calvert
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

The code download link is not wired up.  Looking forward to trying this out once the download is available.

Wednesday, November 04, 2009 6:54 AM by Dave

# re: New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

That's all good, but he doesn't explain why I would want to use one, over and above the extremely simple case shown (overkill!).

Wednesday, November 04, 2009 8:13 AM by Robinson

# re: New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

this is an expression bag... not a method bag.

Thursday, November 12, 2009 6:55 AM by dr.no

# re: New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

Why not use the ExpandoObject class instead?

dynamic contact = new ExpandoObject();

contact.Name = "Patrick Hines";

contact.Phone = "206-555-0144";

contact.Address = new ExpandoObject();

contact.Address.Street = "123 Main St";

contact.Address.City = "Mercer Island";

contact.Address.State = "WA";

contact.Address.Postal = "68402";

http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject%28VS.100%29.aspx

Monday, November 23, 2009 11:36 AM by CoryC

# re: New Article by Bill Wagner on Dynamic Method Bags in C# 4.0

Cory,

I think one of the points of Bill's articles, and his work in general, is to explain the syntax of new features in C#. The ExpandoObject is practical and useful, but it is nice to step behind the scense and see how things work. Bill is particularly good at that, and he does an excellent job of explaining the new Dynamic syntax in this article. Thanks though, for mentioning the ExpandoObject, as it is an important part of this story.

- Charlie

Tuesday, November 24, 2009 8:35 AM by Charlie Calvert

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker