c# - Reflection and Generics get value of property -


i trying implement generic method allows output csv file

public static void writetocsv<t>(list<t> list) t : new()     {         const string attachment = "attachment; filename=personlist.csv";         httpcontext.current.response.clear();         httpcontext.current.response.clearheaders();         httpcontext.current.response.clearcontent();         httpcontext.current.response.addheader("content-disposition", attachment);         httpcontext.current.response.contenttype = "text/csv";         httpcontext.current.response.addheader("pragma", "public");                             bool isfirstrow = true;         foreach (t item in list)         {                             //get public properties             propertyinfo[] propertyinfo = item.gettype().getproperties();              while (isfirstrow)             {                 writecolumnname(propertyinfo);                 isfirstrow = false;             }              type type = typeof (t);              stringbuilder stringbuilder = new stringbuilder();              foreach (propertyinfo info in propertyinfo)             {                    //string value ???? trying value of property info item object              }                             httpcontext.current.response.write(stringbuilder.tostring());             httpcontext.current.response.write(environment.newline);                         }         httpcontext.current.response.end();     } 

but not able value of object's property

any suggestion?

thanks

like this:

object value = info.getvalue(item, null); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -