0

I tried

type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

But this will only return protected fields, this code is declared on the base class, the private field is declared in a derived class, if I make this field protected, it gets returned...

  • 1
    Well, you're not executing the code on the subclass, you're executing the code on the base class. Polymorphism doesn't play a part here; that's *method overriding.* Try executing your code on an instance of the derived class. – Robert Harvey May 21 '22 at 15:19
  • So its not possible to get private members of other classes in the hierarchy? – user2640145 May 21 '22 at 18:24
  • 1
    Try [identifying your derived types](https://stackoverflow.com/questions/2362580/discovering-derived-types-using-reflection) first, then execute your `GetFields` method on each derived type. – Robert Harvey May 21 '22 at 19:10

0 Answers0