Mono Class Library: System.Type Overview | Members

System.Type.DeclaringType Property

Gets the type that declares the type represented by the current instance.

public override Type DeclaringType { get; }

Value

The Type object for the class that declares the type represented by the current instance. If the type is a nested type, this property returns the enclosing type; otherwise, returns the current instance.

Remarks

Note: This property implements the abstract property inherited from Reflection.MemberInfo.

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

For a type parameter of a generic method, this property returns the type that contains the generic method definition.

Example

The following example demonstrates the Type.DeclaringType property.

C# Example

using System;
using System.Reflection;

public abstract class DeclaringTypeTest{
   public abstract class MyClassA {
      public abstract int m(); 
   }
   public abstract class MyClassB : MyClassA {
   }
   public static void Main() { 
      Console.WriteLine("Declaring type of m is {0}",
         typeof(MyClassB).GetMethod("m").DeclaringType);
   }
}
   

The output is

Declaring type of m is DeclaringTypeTest+MyClassA

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0