I have a field that is defined in a base class and when I use reflection on a child object, I want to retrieve the base class where the field is actually defined. Is there a way to do this in C# .Net 4.0?
Alternatively, is there a way to dynamically find the common base class, given 2 different child classes?
The property
FieldInfo.DeclaringTypeshould point to the Type that actually defines the field.This actually comes from
MemberInfoso this will also work for properties, methods, etc..For the second question. This is untested but should work: