Type.DeclaringType Property
Assembly: mscorlib (in mscorlib.dll)
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 namespace System; using namespace System::Reflection; public ref class dtype abstract { public: ref class MyClassA abstract { public: virtual int m() = 0; }; ref class MyClassB abstract: public MyClassA{}; }; int main() { Console::WriteLine( "The declaring type of m is {0}.", dtype::MyClassB::typeid->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.