Marshal.GetITypeInfoForType(Type) Método

Definição

Retorna uma interface ITypeInfo de um tipo gerenciado.

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

Parâmetros

t
Type

O tipo cuja interface ITypeInfo está sendo solicitada.

Retornos

IntPtr

nativeint

Um ponteiro para a interface ITypeInfo para o parâmetro t.

Atributos

Exceções

t não é um tipo visível para COM.

- ou -

té um tipo Windows Runtime.

Uma biblioteca de tipos é registrada para o assembly que contém o tipo, mas não é possível localizar a definição de tipo.

Exemplos

O exemplo a seguir demonstra como recuperar um ponteiro para a ITypeInfo interface de um tipo usando o GetITypeInfoForType método .

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

Comentários

Esse método retorna um ponteiro para uma implementação ITypeInfo baseada no tipo original. Chamar um objeto com faz com GetITypeInfoForType que a contagem de referência seja incrementada no ponteiro da interface antes que o ponteiro seja retornado. Sempre use Marshal.Release para diminuir a contagem de referência depois de terminar com o ponteiro . Você pode aplicar o para substituir o System.Runtime.InteropServices.MarshalAsAttribute comportamento de marshaling de interoperabilidade padrão por esse marshaler personalizado.

Aplica-se a

Confira também