Marshal.GetITypeInfoForType(Type) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 Managed 型別傳回 ITypeInfo 介面。
public:
static IntPtr GetITypeInfoForType(Type ^ t);
public static IntPtr GetITypeInfoForType (Type t);
[System.Security.SecurityCritical]
public static IntPtr GetITypeInfoForType (Type t);
static member GetITypeInfoForType : Type -> nativeint
[<System.Security.SecurityCritical>]
static member GetITypeInfoForType : Type -> nativeint
Public Shared Function GetITypeInfoForType (t As Type) As IntPtr
參數
- t
- Type
正在要求 ITypeInfo
介面的型別。
傳回
IntPtr
nativeint
t
參數的 ITypeInfo
介面指標。
- 屬性
例外狀況
包含型別之組件的型別程式庫已註冊,但找不到型別定義。
範例
下列範例示範如何使用 方法來擷取型 GetITypeInfoForType 別介面的 ITypeInfo
指標。
using System;
using System.Runtime.InteropServices;
class Program
{
static void Run()
{
Console.WriteLine("Calling Marshal.GetITypeInfoForType...");
// Get the ITypeInfo pointer for an Object type
IntPtr pointer = Marshal.GetITypeInfoForType(typeof(object));
Console.WriteLine("Calling Marshal.Release...");
// Always call Marshal.Release to decrement the reference count.
Marshal.Release(pointer);
}
static void Main(string[] args)
{
Run();
}
}
Imports System.Runtime.InteropServices
Module Program
Sub Run()
' Dim a pointer
Dim pointer As IntPtr
Console.WriteLine("Calling Marshal.GetIUnknownForObjectInContext...")
' Get the ITypeInfo pointer for an Object type
pointer = Marshal.GetITypeInfoForType(Type.GetType("System.Object"))
Console.WriteLine("Calling Marshal.Release...")
' Always call Marshal.Release to decrement the reference count.
Marshal.Release(pointer)
End Sub
Sub Main(ByVal args() As String)
Run()
End Sub
End Module
備註
這個方法會根據原始型別傳 ITypeInfo
回實作的指標。 呼叫 具有 的物件 GetITypeInfoForType 會導致參考計數在傳回指標之前,在介面指標上遞增。 當您完成指標之後,一律使用 Marshal.Release 來遞減參考計數。 您可以套用 , System.Runtime.InteropServices.MarshalAsAttribute 以使用此自訂封送處理器取代標準 Interop 封送處理行為。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應