Type.DeclaringType 속성

정의

현재 중첩 형식 또는 제네릭 형식 매개 변수를 선언하는 형식을 가져옵니다.

public:
 abstract property Type ^ DeclaringType { Type ^ get(); };
public:
 virtual property Type ^ DeclaringType { Type ^ get(); };
public abstract Type DeclaringType { get; }
public override Type? DeclaringType { get; }
public override Type DeclaringType { get; }
member this.DeclaringType : Type
Public MustOverride ReadOnly Property DeclaringType As Type
Public Overrides ReadOnly Property DeclaringType As Type

속성 값

Type

현재 형식이 중첩 형식이면 바깥쪽 형식을 나타내고 현재 형식이 제네릭 형식의 형식 매개 변수이면 제네릭 형식 정의를 나타내며 현재 형식이 제네릭 메서드의 형식 매개 변수이면 제네릭 메서드를 선언하는 형식을 나타내는 Type 개체이고, 그렇지 않으면 null입니다.

구현

예제

이 예제에서는 파생 클래스에 있는 메서드의 선언 형식을 표시 합니다.

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 );
}
/* The example produces the following output:

The declaring type of m is dtype+MyClassA.
*/
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);
    }
}
/* The example produces the following output:

The declaring type of m is dtype+MyClassA.
*/
Imports System.Reflection

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

설명

현재 Type 개체가 제네릭 형식의 형식 매개 변수를 나타내는 경우이 속성은 제네릭 형식 정의를 반환 합니다.

현재 Type 개체가 제네릭 메서드의 형식 매개 변수를 나타내는 경우이 속성은 제네릭 메서드 정의가 포함 된 형식을 반환 합니다. 제네릭 형식인 경우 제네릭 형식 정의가 반환 됩니다. 즉, 다음 코드는 제네릭 메서드를 포함 하는 제네릭 클래스의 제네릭 형식 정의를 반환 합니다 List<T> ConvertAll .

Type^ t = List<String^>::typeid->GetMethod("ConvertAll")->GetGenericArguments()[0]->DeclaringType;
Type t = typeof(List<string>).GetMethod("ConvertAll").GetGenericArguments()[0].DeclaringType;
Dim t As Type = GetType(List(Of String)).GetMethod("ConvertAll").GetGenericArguments()(0).DeclaringType

현재이 Type 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우 및 속성은 제네릭 DeclaringType 형식 DeclaringMethod 매개 변수가 원래 정의 된 제네릭 형식 정의 또는 제네릭 메서드 정의를 식별 합니다.

적용 대상

추가 정보