c# - Can't get field through reflection -
c# - Can't get field through reflection -
here class:
public static class root { private static readonly nestedone nestedone; static root() { nestedone = new nestedone(); } class nestedone { private string findme = "blabla"; } } i need field called 'findme' through root. instance of nestedone:
var nestedone = typeof(root).getfield("nestedone", system.reflection.bindingflags.static | system.reflection.bindingflags.nonpublic); but can't further:
var fields = nestedone.gettype().getfields(bindingflags.nonpublic); // there empty please help me
nestedone instance of fieldinfo. calling nestedone.gettype() give instance of type represents fieldinfo type. since type has no fields, empty collection.
what want utilize fieldtype property instead of calling .gettype()
nestedone.fieldtype.getfields(...) you need specify bindingflags.instance flag instance fields.
demo: https://dotnetfiddle.net/kzxvmp
c# reflection
Comments
Post a Comment