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")};