ExpandoObject and XML in C# 4.0

I am working on a .Net project recently and was toying with how to bring in configuration data from an XML file. I thought about creating XSD binding objects, but this felt to restrictive. I thought about creating a map for the data, but when you start nesting maps inside of maps ad nauseam, things can get a little confusing. Then I considered using Linq, but this still seems quite tedious. Then I started doing some reading on ExpandoObjects and the dynamic keyword, introduced in C# 4.0.

After some research and trial and error, I came up with The source code is also available this snippet of code that allowed me to create a dynamic object, based on the structure of the given XML document. Enjoy.

This entry was posted in .Net, C#, MVC2 and tagged , , , , , . Bookmark the permalink.

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 )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.