TypeLibConverter.ConvertTypeLibToAssembly Metoda

Definicja

Konwertuje bibliotekę typów MODELU COM na zestaw.

Przeciążenia

ConvertTypeLibToAssembly(Object, String, Int32, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, Boolean)

Konwertuje bibliotekę typów MODELU COM na zestaw.

ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, String, Version)

Konwertuje bibliotekę typów MODELU COM na zestaw.

ConvertTypeLibToAssembly(Object, String, Int32, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, Boolean)

Konwertuje bibliotekę typów MODELU COM na zestaw.

public:
 virtual System::Reflection::Emit::AssemblyBuilder ^ ConvertTypeLibToAssembly(System::Object ^ typeLib, System::String ^ asmFileName, int flags, System::Runtime::InteropServices::ITypeLibImporterNotifySink ^ notifySink, cli::array <System::Byte> ^ publicKey, System::Reflection::StrongNameKeyPair ^ keyPair, bool unsafeInterfaces);
public System.Reflection.Emit.AssemblyBuilder ConvertTypeLibToAssembly (object typeLib, string asmFileName, int flags, System.Runtime.InteropServices.ITypeLibImporterNotifySink notifySink, byte[] publicKey, System.Reflection.StrongNameKeyPair keyPair, bool unsafeInterfaces);
abstract member ConvertTypeLibToAssembly : obj * string * int * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * bool -> System.Reflection.Emit.AssemblyBuilder
override this.ConvertTypeLibToAssembly : obj * string * int * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * bool -> System.Reflection.Emit.AssemblyBuilder
Public Function ConvertTypeLibToAssembly (typeLib As Object, asmFileName As String, flags As Integer, notifySink As ITypeLibImporterNotifySink, publicKey As Byte(), keyPair As StrongNameKeyPair, unsafeInterfaces As Boolean) As AssemblyBuilder

Parametry

typeLib
Object

Obiekt, który implementuje ITypeLib interfejs.

asmFileName
String

Nazwa pliku wynikowego zestawu.

flags
Int32

Wartość wskazująca TypeLibImporterFlags wszystkie ustawienia specjalne.

notifySink
ITypeLibImporterNotifySink

ITypeLibImporterNotifySink interfejs zaimplementowany przez obiekt wywołujący.

publicKey
Byte[]

Tablica byte zawierająca klucz publiczny.

keyPair
StrongNameKeyPair

StrongNameKeyPair Obiekt zawierający parę publicznych i prywatnych kluczy kryptograficznych.

unsafeInterfaces
Boolean

Jeśli trueinterfejsy wymagają czasu połączenia, sprawdza UnmanagedCode uprawnienia. Jeśli falseinterfejsy wymagają kontroli czasu wykonywania, które wymagają stosu i są droższe, ale pomagają zapewnić większą ochronę.

Zwraca

AssemblyBuilder Obiekt zawierający przekonwertowaną bibliotekę typów.

Implementuje

Wyjątki

typeLib to null.

-lub-

asmFileName to null.

-lub-

notifySink to null.

asmFileName jest pustym ciągiem.

-lub-

asmFileName jest dłuższa niż długość maksymalna zdefiniowana przez system. Aby uzyskać więcej informacji, zobacz PathTooLongException.

flags nie PrimaryInteropAssemblyjest .

-lub-

publicKey i keyPair to null.

Wygenerowane metadane zawierają błędy uniemożliwiające ładowanie jakichkolwiek typów.

Uwagi

Jeśli nie chcesz generować silnej nazwy zestawu, jest to prawidłowe dla publicKey parametru i keyPairnull, o flags ile nie jest równe TypeLibImporterFlags.PrimaryInteropAssembly. W przeciwnym razie należy określić co najmniej jeden z tych parametrów. Jeśli publicKey jest to null, klucz publiczny w keyPair pliku zostanie ustawiony w metadanych manifestu zestawu docelowego, a podpis zostanie wygenerowany na podstawie zawartości zestawu. Jeśli keyPair wartość to null, publicKey zostanie ustawiona w metadanych manifestu zestawu docelowego, a podpis nie zostanie wygenerowany. Określanie obu parametrów nie jest ogólnie przydatne i może spowodować nieprawidłowy podpis.

Aby uzyskać więcej informacji na ITypeLibtemat programu , zobacz istniejącą dokumentację w bibliotece MSDN.

Dotyczy

ConvertTypeLibToAssembly(Object, String, TypeLibImporterFlags, ITypeLibImporterNotifySink, Byte[], StrongNameKeyPair, String, Version)

Konwertuje bibliotekę typów MODELU COM na zestaw.

public:
 virtual System::Reflection::Emit::AssemblyBuilder ^ ConvertTypeLibToAssembly(System::Object ^ typeLib, System::String ^ asmFileName, System::Runtime::InteropServices::TypeLibImporterFlags flags, System::Runtime::InteropServices::ITypeLibImporterNotifySink ^ notifySink, cli::array <System::Byte> ^ publicKey, System::Reflection::StrongNameKeyPair ^ keyPair, System::String ^ asmNamespace, Version ^ asmVersion);
public System.Reflection.Emit.AssemblyBuilder ConvertTypeLibToAssembly (object typeLib, string asmFileName, System.Runtime.InteropServices.TypeLibImporterFlags flags, System.Runtime.InteropServices.ITypeLibImporterNotifySink notifySink, byte[] publicKey, System.Reflection.StrongNameKeyPair keyPair, string asmNamespace, Version asmVersion);
abstract member ConvertTypeLibToAssembly : obj * string * System.Runtime.InteropServices.TypeLibImporterFlags * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * string * Version -> System.Reflection.Emit.AssemblyBuilder
override this.ConvertTypeLibToAssembly : obj * string * System.Runtime.InteropServices.TypeLibImporterFlags * System.Runtime.InteropServices.ITypeLibImporterNotifySink * byte[] * System.Reflection.StrongNameKeyPair * string * Version -> System.Reflection.Emit.AssemblyBuilder
Public Function ConvertTypeLibToAssembly (typeLib As Object, asmFileName As String, flags As TypeLibImporterFlags, notifySink As ITypeLibImporterNotifySink, publicKey As Byte(), keyPair As StrongNameKeyPair, asmNamespace As String, asmVersion As Version) As AssemblyBuilder

Parametry

typeLib
Object

Obiekt, który implementuje ITypeLib interfejs.

asmFileName
String

Nazwa pliku wynikowego zestawu.

flags
TypeLibImporterFlags

Wartość wskazująca TypeLibImporterFlags wszystkie ustawienia specjalne.

notifySink
ITypeLibImporterNotifySink

ITypeLibImporterNotifySink interfejs zaimplementowany przez obiekt wywołujący.

publicKey
Byte[]

Tablica byte zawierająca klucz publiczny.

keyPair
StrongNameKeyPair

StrongNameKeyPair Obiekt zawierający parę publicznych i prywatnych kluczy kryptograficznych.

asmNamespace
String

Przestrzeń nazw wynikowego zestawu.

asmVersion
Version

Wersja wynikowego zestawu. Jeśli nulljest używana wersja biblioteki typów.

Zwraca

AssemblyBuilder Obiekt zawierający przekonwertowaną bibliotekę typów.

Implementuje

Wyjątki

typeLib to null.

-lub-

asmFileName to null.

-lub-

notifySink to null.

asmFileName jest pustym ciągiem.

-lub-

asmFileName jest dłuższa niż długość maksymalna zdefiniowana przez system. Aby uzyskać więcej informacji, zobacz PathTooLongException.

flags nie PrimaryInteropAssemblyjest .

-lub-

publicKey i keyPair to null.

Wygenerowane metadane zawierają błędy uniemożliwiające ładowanie jakichkolwiek typów.

Przykłady

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Runtime::InteropServices;

enum class RegKind
{
   RegKind_Default, RegKind_Register, RegKind_None
};

ref class ConversionEventHandler: public ITypeLibImporterNotifySink
{
public:
   virtual void ReportEvent( ImporterEventKind eventKind, int eventCode, String^ eventMsg )
   {
      
      // handle warning event here...
   }

   virtual Assembly^ ResolveRef( Object^ typeLib )
   {
      
      // resolve reference here and return a correct assembly...
      return nullptr;
   }

};


[DllImport("oleaut32.dll",CharSet=CharSet::Unicode,PreserveSig=false)]
extern void LoadTypeLibEx( String^ strTypeLibName, RegKind regkind,
         [MarshalAs(UnmanagedType::Interface)] interior_ptr<Object^> typeLib );

int main()
{
   Object^ typeLib = gcnew Object;
   LoadTypeLibEx( "SHDocVw.dll", RegKind::RegKind_None,  &typeLib );
   if ( typeLib == nullptr )
   {
      Console::WriteLine( "LoadTypeLibEx failed." );
      return 0;
   }

   TypeLibConverter^ converter = gcnew TypeLibConverter;
   ConversionEventHandler^ eventHandler = gcnew ConversionEventHandler;
   AssemblyBuilder^ asmb = converter->ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", (System::Runtime::InteropServices::TypeLibImporterFlags)0, eventHandler, nullptr, nullptr, nullptr, nullptr );
   asmb->Save( "ExplorerLib.dll" );
}
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;

public class App
{
    private enum RegKind
    {
        RegKind_Default = 0,
        RegKind_Register = 1,
        RegKind_None = 2
    }
    
    [ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
    private static extern void LoadTypeLibEx( String strTypeLibName, RegKind regKind, 
        [ MarshalAs( UnmanagedType.Interface )] out Object typeLib );
    
    public static void Main()
    {
        Object typeLib;
        LoadTypeLibEx( "SHDocVw.dll", RegKind.RegKind_None, out typeLib ); 
        
        if( typeLib == null )
        {
            Console.WriteLine( "LoadTypeLibEx failed." );
            return;
        }
            
        TypeLibConverter converter = new TypeLibConverter();
        ConversionEventHandler eventHandler = new ConversionEventHandler();
        AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib, "ExplorerLib.dll", 0, eventHandler, null, null, null, null );	
        asm.Save( "ExplorerLib.dll" );
    }
}

public class ConversionEventHandler : ITypeLibImporterNotifySink
{
    public void ReportEvent( ImporterEventKind eventKind, int eventCode, string eventMsg )
    {
        // handle warning event here...
    }
    
    public Assembly ResolveRef( object typeLib )
    {
        // resolve reference here and return a correct assembly...
        return null; 
    }	
}
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Runtime.InteropServices

Public Class App
    Private Enum RegKind
        RegKind_Default = 0
        RegKind_Register = 1
        RegKind_None = 2
    End Enum 'RegKind

    <DllImport("oleaut32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Private Shared Sub LoadTypeLibEx(ByVal strTypeLibName As [String], ByVal regKind As RegKind, <MarshalAs(UnmanagedType.Interface)> ByRef typeLib As [Object])
    End Sub

    Public Shared Sub Main()
        Dim typeLib As [Object]
        LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, typeLib)

        If typeLib Is Nothing Then
            Console.WriteLine("LoadTypeLibEx failed.")
            Return
        End If

        Dim converter As New TypeLibConverter()
        Dim eventHandler As New ConversionEventHandler()
        Dim asm As AssemblyBuilder = converter.ConvertTypeLibToAssembly(typeLib, "ExplorerLib.dll", 0, eventHandler, Nothing, Nothing, Nothing, Nothing)
        asm.Save("ExplorerLib.dll")
    End Sub
End Class
 _

Public Class ConversionEventHandler
    Implements ITypeLibImporterNotifySink

    Public Sub ReportEvent(ByVal eventKind As ImporterEventKind, ByVal eventCode As Integer, ByVal eventMsg As String) Implements ITypeLibImporterNotifySink.ReportEvent
        ' handle warning event here...
    End Sub

    Public Function ResolveRef(ByVal typeLib As Object) As [Assembly] Implements ITypeLibImporterNotifySink.ResolveRef
        ' resolve reference here and return a correct assembly...
        Return Nothing
    End Function 'ResolveRef
End Class

Uwagi

Jeśli nie chcesz generować silnej nazwy zestawu, jest to prawidłowe dla publicKey parametru i keyPairnull, o flags ile nie jest równe TypeLibImporterFlags.PrimaryInteropAssembly. W przeciwnym razie należy określić jeden z tych parametrów. Jeśli publicKey jest to null, klucz publiczny w keyPair pliku zostanie ustawiony w metadanych manifestu zestawu docelowego, a podpis zostanie wygenerowany na podstawie zawartości zestawu. Jeśli keyPair wartość to null, publicKey zostanie ustawiona w metadanych manifestu zestawu docelowego, a podpis nie zostanie wygenerowany. Określanie obu parametrów nie jest ogólnie przydatne i może spowodować nieprawidłowy podpis.

Aby uzyskać więcej informacji na ITypeLibtemat programu , zobacz istniejącą dokumentację w bibliotece MSDN.

Dotyczy