In C#, when I’m reflecting over a derived type, how come I don’t see base classes’ static fields?
I’ve tried both type.GetFields(BindingFlags.Static) and type.GetFields().
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is how it works.
staticmembers are really non-object-oriented stuff. They are not polymorphic and they really belong to their declaring type and are unrelated to other types in the inheritance hierarchy. For instance, a static initializer for a base class is not required to run before accessing a static member in a derived class.staticmembers of base classes are not returned unlessBindingFlags.FlattenHierarchyis specified: