DeclaringType Property
Collapse the table of content
Expand the table of content

MemberInfo::DeclaringType Property

 

Gets the class that declares this member.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public:
property Type^ DeclaringType {
	virtual Type^ get() abstract;
}

Property Value

Type: System::Type^

The Type object for the class that declares this member.

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 null.

The following example defines an interface, IValue, with a single member, GetValue. It also defines four classes: A, a base class that implements the IValue interface; B, which inherits from A and hides its implementation of GetValue from the base class implementation; C, which simply inherits from A; and D, which inherits from A and overrides its GetValue method. The example then retrieves a MemberInfo object for each member of the type (including members inherited from Object) and displays the value of its DeclaringType property.

No code example is currently available or this language may not be supported.

Note that the declaring type of A.GetValue is A, that B includes two GetValue methods, one declared by A and one by B, and that the declaring type of D.GetValue is D.

System_CAPS_noteNote

DeclaringType returns only the member names and the names of their declaring types. To return the member names with their prototypes, call MemberInfo.ToString.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft