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.
This topic has not yet been rated - Rate this topic

Type.DeclaringType Property

Gets the class that declares this member.

[Visual Basic]
Overrides Public ReadOnly Property DeclaringType As Type
[C#]
public override Type DeclaringType {get;}
[C++]
public: __property Type* get_DeclaringType();
[JScript]
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.

Remarks

This property implements the abstract property inherited from MemberInfo.

Example

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

[Visual Basic] 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public MustInherit Class dtype

    Public MustInherit Class MyClassA
        Public MustOverride Function m() As Integer
    End Class

    Public MustInherit Class MyClassB
        Inherits MyClassA
    End Class

    Public Shared Sub Main()
        Console.WriteLine("The declaring type of m is {0}.", _
           GetType(MyClassB).GetMethod("m").DeclaringType)
    End Sub
End Class

[C#] 
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);
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

public __abstract __gc class dtype 
{

public:
   __abstract __gc class MyClassA 
   {
   public:
      virtual int m() = 0;
   };

   __abstract __gc class MyClassB : public MyClassA 
   {
   };

};

int main()
{
   Console::WriteLine(S"The declaring type of m is {0}.",
      __typeof(dtype::MyClassB)->GetMethod(S"m")->DeclaringType);
}

[JScript] 
import System;
import System.Reflection;

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

dtype.Main();

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | MemberInfo | ReflectedType

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.