Marshal.GetITypeInfoForType(Type) Метод

Определение

Возвращает интерфейс 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

Указатель на интерфейс ITypeInfo для параметра t.

Атрибуты

Исключения

t не является типом, видимым для модели COM.

-или-

t— это тип среда выполнения Windows.

Библиотека типов зарегистрирована для сборки, содержащей тип, но определение типа не найдено.

Примеры

В следующем примере показано, как получить указатель на 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 режима маршалинга взаимодействия этим пользовательским маршалером.

Применяется к

См. также раздел