Aracılığıyla paylaş


Type.DeclaringType Özellik

Tanım

Geçerli iç içe türü veya genel tür parametresini bildiren türü alır.

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

Özellik Değeri

Type Geçerli tür iç içe bir türse kapsayan türü veya genel tür tanımını temsil eden bir nesne, geçerli tür genel bir türün tür parametresiyse veya genel yöntemi bildiren türse, geçerli tür genel bir yöntemin tür parametresiyse, aksi takdirde, null.

Uygulamalar

Örnekler

Bu örnek, türetilmiş bir sınıftaki bir yöntemin bildirim türünü görüntüler.

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

Açıklamalar

Geçerli Type nesne genel türdeki bir tür parametresini temsil ederse, bu özellik genel tür tanımını döndürür.

Geçerli Type nesne genel bir yöntemin tür parametresini temsil ederse, bu özellik genel yöntem tanımını içeren türü döndürür. Tür genelse, genel tür tanımı döndürülür. Yani, aşağıdaki kod genel yöntemini içeren ConvertAll genel sınıfın List<T> genel tür tanımını döndürür:

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

GeçerliType, genel bir tür veya genel yöntemin tanımında tür parametresini temsil ediyorsa ve DeclaringMethod özellikleri, DeclaringType genel tür parametresinin başlangıçta tanımlandığı genel tür tanımını veya genel yöntem tanımını tanımlar:

Şunlara uygulanır

Ayrıca bkz.