Marshal.GetITypeInfoForType(Type) Método

Definición

Devuelve una interfaz ITypeInfo de un tipo administrado.

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

Tipo cuya interfaz ITypeInfo se está solicitando.

Devoluciones

IntPtr

nativeint

Puntero a la interfaz ITypeInfo para el parámetro t.

Atributos

Excepciones

t no es un tipo visible para COM.

o bien

tes un tipo de Windows Runtime.

Se registra una biblioteca de tipos para el ensamblado que contiene el tipo, pero no se encuentra la definición de tipo.

Ejemplos

En el ejemplo siguiente se muestra cómo recuperar un puntero a la ITypeInfo interfaz de un tipo mediante el 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

Comentarios

Este método devuelve un puntero a una ITypeInfo implementación basada en el tipo original. Llamar a un objeto con GetITypeInfoForType hace que el recuento de referencias aumente en el puntero de interfaz antes de que se devuelva el puntero. Marshal.Release Use siempre para disminuir el recuento de referencias una vez que haya terminado con el puntero. Puede aplicar para reemplazar el System.Runtime.InteropServices.MarshalAsAttribute comportamiento de serialización de interoperabilidad estándar por este serializador personalizado.

Se aplica a

Consulte también