Share via


Marshal.GetITypeInfoForType(Type) Méthode

Définition

Retourne une interface ITypeInfo à partir d'un type managé.

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

Paramètres

t
Type

Type dont l'interface ITypeInfo est demandée.

Retours

IntPtr

nativeint

Pointeur vers l'interface ITypeInfo du paramètre t.

Attributs

Exceptions

t n’est pas un type visible par COM.

- ou -

test un type Windows Runtime.

Une bibliothèque de types est inscrite pour l’assembly qui contient le type, mais la définition de type est introuvable.

Exemples

L’exemple suivant montre comment récupérer un pointeur vers l’interface ITypeInfo d’un type à l’aide de la GetITypeInfoForType méthode .

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

Remarques

Cette méthode retourne un pointeur vers une ITypeInfo implémentation basée sur le type d’origine. L’appel d’un objet avec GetITypeInfoForType entraîne l’incrémentation du nombre de références sur le pointeur d’interface avant que le pointeur ne soit retourné. Marshal.Release Utilisez toujours pour décrémenter le nombre de références une fois que vous avez terminé avec le pointeur. Vous pouvez appliquer le pour remplacer le System.Runtime.InteropServices.MarshalAsAttribute comportement de marshaling d’interopérabilité standard par ce marshaleur personnalisé.

S’applique à

Voir aussi