Marshal.GetITypeInfoForType(Type) Metoda

Definicja

ITypeInfo Zwraca interfejs z typu zarządzanego.

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

Parametry

t
Type

Typ, którego ITypeInfo interfejs jest wymagany.

Zwraca

IntPtr

nativeint

Wskaźnik do interfejsu ITypeInfo dla parametru t .

Atrybuty

Wyjątki

t nie jest widocznym typem modelu COM.

-lub-

tjest typem środowisko wykonawcze systemu Windows.

Biblioteka typów jest zarejestrowana dla zestawu zawierającego typ, ale nie można odnaleźć definicji typu.

Przykłady

W poniższym przykładzie pokazano, jak pobrać wskaźnik do interfejsu ITypeInfo dla typu przy użyciu GetITypeInfoForType metody .

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

Uwagi

Ta metoda zwraca wskaźnik do ITypeInfo implementacji opartej na oryginalnym typie. Wywołanie obiektu z GetITypeInfoForType powoduje, że liczba odwołań zwiększa się w wskaźniku interfejsu przed zwróceniem wskaźnika. Zawsze używaj polecenia Marshal.Release , aby odkreślić liczbę odwołań po zakończeniu pracy ze wskaźnikiem. Można zastosować element System.Runtime.InteropServices.MarshalAsAttribute , aby zastąpić standardowe działanie marshalingu międzyoperacyjnej tym niestandardowym marshalerem.

Dotyczy

Zobacz też