c# - Create Object and its Properties at Run-time from List -
i need create dynamic object , properties @ run-time create instance of object store values.
why want above logic!
i reading excel file in c# , first line of code header properties , followed each rows record instance of dynamic object.
list<string> exceldataheader = new list<string>(); (int y = 2; y <= colcount; y++) { exceldataheader.add(xlrange.cells[headerrow, y].value2.tostring()); } dynamic mydynamic = new system.dynamic.expandoobject(); ??????????
i need return excel read data in object
you could use expandoobject
here - it'll work, need use dictionary api:
idictionary<string, object> obj = new expandoobject(); obj["id"] = 123; obj["name"] = "fred"; // "dynamic" bit: dynamic dyn = obj; int id = dyn.id; // 123 string name = dyn.name; // "fred"
however, fail see point. since won't referring object in c# code things obj.propertyname
, dynamic
has little purpose. might store each record in dictionary<string,object>
or similar. given describe, there no places use mydynamic
dynamic
object.
Comments
Post a Comment