Dynamic columns via DynamicObject

This might be obvious to some of you, but I thought of writing a small post, since it has a nice example of the usage of  .NET 4. DynamicObject.

Recently I had a requirement where I had to dynamically generate a tabular data (rows/cols) and use that data for Json serialization.

There are few ways of implementing this. The below example uses the .NET 4. DynamicObject to generate custom columns. I found this is quite easier and cleaner to implement than the tradition reflection based approach.

var columnsSet1 = new List<Col>() {new Col("row1Col1"),
new Col("row1Col2"), new Col("row1Col3")};
var columnsSet2 = new List<Col>() {new Col("row2Col1"),
new Col("row2Col2"), new Col("row2Col3")};

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 )

Google+ photo

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

Connecting to %s