Marshal.GetITypeInfoForType(Type) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne une ITypeInfo interface à 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 ITypeInfo l’interface est demandée.
Retours
nativeint
Pointeur vers l’interface ITypeInfo du t paramètre.
- Attributs
Exceptions
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 provoque GetITypeInfoForType l’incrémentation du nombre de références sur le pointeur d’interface avant le retour du pointeur. Utilisez Marshal.Release toujours pour décrémenter le nombre de références une fois le pointeur terminé. Vous pouvez appliquer le System.Runtime.InteropServices.MarshalAsAttribute comportement de marshaling d’interopérabilité standard à ce marshaleur personnalisé.