.net - C#, How to simply change order of class members -
hi have class derived class . :
public class customer { public string date{ get; set; } public string installationno{ get; set; } public string serialno { get; set; } }
then have created class named customer_u derived customer
public class customer_u:customer { public string bill{ get; set; } }
i have simple question. have google many time no answer. have list filled data like:
list<customer_u> customer= new list<customer_u>()
create excel using list. in excel colum order :
bill --- date --- installtionno --- serialno.
idont want order. want "bill" member last columns . how set order of member when createin class derived class
there no defined order in clr class; implementation inspecting metadata of class determine how class interpreted.
for example, excel library using reflection inspect class pass , reflection makes no guarantees order in things processed.
other implementations such wcf datacontractserializer or protobuf.net handle order through use of datamember.
that said, if library can handle dynamic or anonymous types can use approach detailed in other answers. .net seems consistently reflect these types in same order created.
var x = new { z = "", y = 1, x = true }; console.writeline(x.gettype().getproperties().select(y => y.name));
however should noted implementation detail , should not relied upon. i'd see if library allows specify mapping between properties in class , columns in spreadsheet otherwise might run weird bugs in future!
Comments
Post a Comment