Type.DeclaringType 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 중첩 형식 또는 제네릭 형식 매개 변수를 선언하는 형식을 가져옵니다.
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 현재 형식이 중첩 형식인 경우 바깥쪽 형식을 나타내는 개체이거나, 제네릭 형식이 제네릭 형식의 형식 매개 변수인 경우 제네릭 형식 정의이거나, 제네릭 메서드를 선언하는 형식이거나, 현재 형식이 제네릭 메서드null의 형식 매개 변수인 경우 해당 형식입니다.
구현
예제
다음은 파생 클래스에서 메서드의 선언 형식을 표시하는 예제입니다.
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.
*/
[<AbstractClass>]
type MyClassA() =
abstract m: unit -> int
[<AbstractClass>]
type MyClassB() =
inherit MyClassA()
printfn $"""The declaring type of m is {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 = typeof(List<string>).GetMethod("ConvertAll").GetGenericArguments()[0].DeclaringType;
let t = typeof<ResizeArray<string>>.GetMethod("ConvertAll").GetGenericArguments().[0].DeclaringType
Dim t As Type = GetType(List(Of String)).GetMethod("ConvertAll").GetGenericArguments()(0).DeclaringType
현재 Type 제네릭 형식 또는 제네릭 메서드 DeclaringType 의 정의에서 형식 매개 변수를 나타내는 경우 및 DeclaringMethod 속성은 제네릭 형식 매개 변수가 원래 정의된 제네릭 형식 정의 또는 제네릭 메서드 정의를 식별합니다.
속성이 DeclaringMethod 제네릭 메서드 정의를 나타내는 형식 MethodInfo 을 반환MethodInfo하고 현재 Type 개체가 해당 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우
속성이 DeclaringMethod 반환
null되면 속성은 DeclaringType 항상 제네릭 형식 정의를 나타내는 개체를 반환 Type 하고 현재 Type 개체는 해당 제네릭 형식 정의의 형식 매개 변수를 나타냅니다.속성이 DeclaringType throw되는
false형식 IsGenericParameter 에서 속성을 가져옵니다InvalidOperationException.