Marshal.GetITypeInfoForType(Type) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
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 ITypeInfo interface está sendo solicitada.
Retornos
nativeint
Um ponteiro para a ITypeInfo interface do t parâmetro.
- Atributos
Exceções
Uma biblioteca de tipos é registrada para o assembly que contém o tipo, mas a definição de tipo não pode ser encontrada.
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 incremente 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 System.Runtime.InteropServices.MarshalAsAttribute comportamento de marshaling de interoperabilidade padrão por esse marshaler personalizado.