c# - How to get value from the object but its type is unreachable -
for instance, in current class, there hashtable,
hashtable t = gethashable(); //get somewhere. var b = t["key"];
the type of b hidden current class, unreachable, not public class type.
but want value b, example b has field call "id", need id b.
is there anyway can it, reflection ???
if don't know type, you'll need reflection:
object b = t["key"]; type typeb = b.gettype(); // if id property object value = typeb.getproperty("id").getvalue(b, null); // if id field object value = typeb.getfield("id").getvalue(b);
Comments
Post a Comment