Export (0) Print
Expand All

Type.DeclaringType Property

Gets the type that declares the current nested type or generic type parameter.

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

abstract DeclaringType : Type
override DeclaringType : Type

Property Value

Type: System.Type
A Type object representing the enclosing type, if the current type is a nested type; or the generic type definition, if the current type is a type parameter of a generic type; or the type that declares the generic method, if the current type is a type parameter of a generic method; otherwise, a null reference (Nothing in Visual Basic).

Implements

_Type.DeclaringType
_MemberInfo.DeclaringType

If the current Type object represents a type parameter of a generic type, this property returns the generic type definition.

If the current Type object represents a type parameter of a generic method, this property returns the type that contains the generic method definition. If the type is generic, the generic type definition is returned. That is, the following code returns the generic type definition of the List(T) generic class, which contains the ConvertAll(TOutput) generic method:

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

If the current Type represents a type parameter in the definition of a generic type or generic method, the DeclaringType and DeclaringMethod properties identify the generic type definition or generic method definition where the generic type parameter was originally defined:

  • If the DeclaringMethod property returns a MethodInfo, that MethodInfo represents a generic method definition, and the current Type object represents a type parameter of that generic method definition.

  • If the DeclaringMethod property returns a null reference (Nothing in Visual Basic), then the DeclaringType property always returns a Type object representing a generic type definition, and the current Type object represents a type parameter of that generic type definition.

  • Getting the DeclaringType property on a type whose IsGenericParameter property is false throws an InvalidOperationException.

This example displays the declaring type of a method in a derived class.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft