c # get values by member name

PropertyInfo [] info = ( typeof (ShopItem)) GetProperties ();. 
ShopItem m; // assumed that this object is not empty (specific value) 
/ * 
Take a first member attribute, assume that the first member of the attribute name is id, type is long, if you know the specific name can be a member of the "info [0] .Name" replace you know the name of a member, such as "the above mentioned id" 
* /                    
Long the Result = typeof (ShopItem) .GetProperty (info [ 0 ] .Name) .getValue (m);

 

Guess you like

Origin www.cnblogs.com/Transmuter/p/11520985.html