c# - Getting inherited public static field with Reflection in Portable Class Libraries -
within portable class library, have 2 classes:
the parent
public class parent { public string inherited; public static string inheritedstatic; }
and child derives it
public class child : parent { public static string mine; }
the problem cannot inherited static field named "inheritedstate", non-static ("inherited").
this code i'm running:
class program { static void main(string[] args) { var childfields = typeof(child).gettypeinfo().getruntimefields(); foreach (var fieldinfo in childfields) { console.writeline(fieldinfo); } } }
what should inherited static field? thanks!
you use:
public static fieldinfo[] declaredfields(typeinfo type) { var fields = new list<fieldinfo>(); while (type != null) { fields.addrange(type.declaredfields); type type2 = type.basetype; type = type2 != null ? type2.gettypeinfo() : null; } return fields.toarray(); }
Comments
Post a Comment