Marshal.GetITypeInfoForType(Type) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從受管理型態回傳 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
一個參數ITypeInfot介面的指標。
- 屬性
例外狀況
一個型別庫是為包含該型別的組合註冊的,但找不到型別定義。
範例
以下範例示範如何利用該ITypeInfo方法取得某GetITypeInfoForType個型態介面的指標。
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 取代標準的互操作編組行為。