I am trying to create a function that accepts a generic List<T> and iterates the list returning an excel file byte[]. The function needs be able to determine the objects properties. So if i pass a List<person> and person has properties first, last, age, etc i need to be able to determine the property names in order to create the excel column headers and then i need to iterate the list to assign the property values to the column cells. Can anyone point me to some sample code for working with List<T> in a generic function?
I am trying to create a function that accepts a generic List<T> and iterates
Share
Aside: for getting columns back in a known order: there is no defined order for members, except that which you create. For example (from MSDN):
If you don’t need to rely on the order, either reflection or TypeDescriptor would do; for example (noting that this writes TSV text, not
byte[]– my interpretation is that the problem is getting the data, not writing the Excel):If you need order, you would need to either:
params string[] propertyNames)The
TypeDescriptorapproach above has the advantages (overGetType().GetProperties()) that:DataView, for example, if you useIList)