c# - Get FieldInfo of inherited class -


in c# have classes derived in following way:

myclass1 <- myclass2 <- myclass3 <- myclass4 (the root class myclass1) 

now have instance of myclass4 myclass4. how private field info declared in myclass2? can following:

fieldinfo[] fields = model.gettype().basetype.basetype.                        getfields(bindingflags.nonpublic | bindingflags.instance); foreach (fieldinfo fld in field) {     .... } 

what if inheritance level unknown?

do know looking field in myclass2? if so, keep reading currenttype.basetype until currenttype == typeof(myclass2).

iow

type lcurrenttype = model.gettype(); while (lcurrenttype != typeof(myclass2) && lcurrenttype != null) {     lcurrenttype = lcurrenttype.basetype; } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -