Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.DeclaringType Property

Gets the class that declares this member.

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

public override Type DeclaringType { get; }
/** @property */
public Type get_DeclaringType ()

public override function get DeclaringType () : Type

Property Value

The Type object for the class that declares this member. If the type is a nested type, this property returns the enclosing type.

This property implements the abstract property inherited from MemberInfo.

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.

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

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

using System;
using System.Reflection;
 
public abstract class dtype 
{
    
    public abstract class MyClassA 
    {
        public abstract int m(); 
    }
    
    public abstract class MyClassB : MyClassA 
    {
    }
  
    public static void Main(string[] args) 
    { 
        Console.WriteLine("The declaring type of m is {0}.",
            typeof(MyClassB).GetMethod("m").DeclaringType);
    }
}

import System.*;
import System.Reflection.*;

abstract public class Dtype
{
    abstract public class MyClassA
    {
        public abstract int M();
    } //MyClassA
      
    abstract public class MyClassB extends MyClassA
    {
    } //MyClassB
   
    public static void main(String[] args)
    {
        Console.WriteLine("The declaring type of M is {0}.", 
        MyClassB.class.ToType().GetMethod("M").get_DeclaringType());
    } //main
} //Dtype

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft