1

my application read Excel sheets and display it as a table. What I do is reading DataTable and putting data in an object of type:

List<List<string>>

To display data on the page I use 2 loops (inner and outer) to recreate the table.

What I'd like to do is to create a new type MyType, for instance. Then add properties to it depending in number and value types to the headers of the Excel data. I believe it's easier to work with type.

Thanks for helping

Richard77
  • 20,343
  • 46
  • 150
  • 252

3 Answers3

2

I think you may be looking for ExpandoObject, which lets you add arbitrary properties to each object at run-time. For example:

dynamic obj = new ExpandoObject();      // initially empty object
obj.Spread = "Nutella";   // obj now has a “Spread” property of type string

Of course, you can then put this object into a List<dynamic> along with all the other objects.

Timwi
  • 65,159
  • 33
  • 165
  • 230
1

You can do it using reflection.
take a look at the TypeBuilder class

Itay Karo
  • 17,924
  • 4
  • 40
  • 58
0

Maybe anonymous types?

http://msdn.microsoft.com/en-us/library/bb397696.aspx

You do need to set the properties all in one go, though.

crdx
  • 1,412
  • 13
  • 26