DynamicMethod.DeclaringType 屬性

定義

取得宣告方法的類型,如果是動態方法,則一律為 null

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

屬性值

一定是 null

範例

下列程式代碼範例會顯示動態方法的宣告類型。 此程式代碼範例是針對 類別提供的較大範例的 DynamicMethod 一部分。

// Display the declaring type, which is always null for dynamic
// methods.
if (hello->DeclaringType == nullptr)
{
    Console::WriteLine("\r\nDeclaringType is always null for dynamic methods.");
}
else
{
    Console::WriteLine("DeclaringType: {0}", hello->DeclaringType);
}
// Display the declaring type, which is always null for dynamic
// methods.
if (hello.DeclaringType == null)
{
    Console.WriteLine("\r\nDeclaringType is always null for dynamic methods.");
}
else
{
    Console.WriteLine("DeclaringType: {0}", hello.DeclaringType);
}
' Display the declaring type, which is always Nothing for dynamic
' methods.
If hello.DeclaringType Is Nothing Then
    Console.WriteLine(vbCrLf & "DeclaringType is always Nothing for dynamic methods.")
Else
    Console.WriteLine("DeclaringType: {0}", hello.DeclaringType)
End If

備註

這個屬性一律會 null 針對動態方法傳回 。 即使動態方法以邏輯方式與類型相關聯,它也不會由類型宣告。

適用於