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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -