MemberInfo::DeclaringType Property
Gets the class that declares this member.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
The DeclaringType property retrieves a reference to the Type object for the type that declares this member. A member of a type is either declared by the type or inherited from a base type, so the Type object returned by the DeclaringType property might not be the same as the Type object used to obtain the current MemberInfo object.
If the Type object from which this MemberInfo object was obtained did not declare this member, the DeclaringType property will represent one of its base types.
If the MemberInfo object is a global member (that is, if it was obtained from the Module::GetMethods method, which returns global methods on a module), the returned DeclaringType will be nullptr.
The following example shows how DeclaringType works with classes and interfaces. It uses a helper method named FormatDeclaringType to show how the declaring type of method M changes in classes that implement interfaces or that override and inherit from base classes.
For example, when class B overrides virtual method M from class A, it essentially redefines (or redeclares) this method. Therefore, the MethodInfo for B.M reports the declaring type as B instead of A, although A is where this method was originally declared.
The example also lists the names and declaring types of all the members of class C.
Note: |
|---|
To run this example, see Building Examples That Use a Demo Method and a TextBlock Control. |
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Note: