c# - GetFields of derived type -
i trying reflect fields in derived type it's returning fields of base type.
public class basetype { string basevar; } public class derivedtype : basetype { string derivedvar; }
in function:
derivedtype derived = new derivedtype(); fieldinfo[] fields = derived.gettype().getfields();
this return basevar, not derivedvar. i've tried different bindings , doesn't seem make difference.
also, i'm doing in asp.net within app_code basevar defined in app_code , derivedvar user control defined in app_controls types not in scope.
as is, return nothing default binding public fields only.
as also, derivedtype isn't derived basetype
with:
fieldinfo[] fields = derived.gettype().getfields(bindingflags.nonpublic | bindingflags.instance);
it returns derivedvar. i've checked in linqpad.
if change derivedtype derived basetype, can both fields with:
fieldinfo[] fields = derived.gettype().getfields(bindingflags.nonpublic | bindingflags.instance).concat(derived.gettype().basetype.getfields(bindingflags.nonpublic | bindingflags.instance)).toarray();
Comments
Post a Comment