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 接口的类型。
返回
nativeint
指向 t 参数的 ITypeInfo 接口的指针。
- 属性
 
例外
为包含一个类型的程序集注册了该类型的类型库,但找不到类型定义。
示例
以下示例演示如何使用 方法检索指向 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 标准互操作封送处理行为替换为此自定义封送处理程序。