Читати англійською Редагувати

Поділитися через


TypeLibConverter.ConvertAssemblyToTypeLib Method

Definition

Converts an assembly to a COM type library.

C#
public object ConvertAssemblyToTypeLib(System.Reflection.Assembly assembly, string strTypeLibName, System.Runtime.InteropServices.TypeLibExporterFlags flags, System.Runtime.InteropServices.ITypeLibExporterNotifySink notifySink);

Parameters

assembly
Assembly

The assembly to convert.

strTypeLibName
String

The file name of the resulting type library.

flags
TypeLibExporterFlags

A TypeLibExporterFlags value indicating any special settings.

notifySink
ITypeLibExporterNotifySink

The ITypeLibExporterNotifySink interface implemented by the caller.

Returns

An object that implements the ITypeLib interface.

Implements

Examples

C#
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;

[ComImport,
GuidAttribute( "00020406-0000-0000-C000-000000000046" ),
InterfaceTypeAttribute( ComInterfaceType.InterfaceIsIUnknown ),
ComVisible( false )]
public interface UCOMICreateITypeLib
{
    void CreateTypeInfo();
    void SetName();
    void SetVersion();
    void SetGuid();
    void SetDocString();
    void SetHelpFileName();
    void SetHelpContext();
    void SetLcid();
    void SetLibFlags();
    void SaveAllChanges();
}

public class App
{
    public static void Main()
    {
        Assembly asm = Assembly.LoadFrom( "MyAssembly.dll" );
        TypeLibConverter converter = new TypeLibConverter();
        ConversionEventHandler eventHandler = new ConversionEventHandler();
        
        UCOMICreateITypeLib typeLib = (UCOMICreateITypeLib)converter.ConvertAssemblyToTypeLib( asm, "MyTypeLib.dll", 0, eventHandler );	
        typeLib.SaveAllChanges();
    }
}

public class ConversionEventHandler : ITypeLibExporterNotifySink
{
    public void ReportEvent( ExporterEventKind eventKind, int eventCode, string eventMsg )
    {
        // Handle the warning event here.
    }
    
    public Object ResolveRef( Assembly asm )
    {
        // Resolve the reference here and return a correct type library.
        return null; 
    }	
}

Remarks

For more information on ITypeLib, please see its existing documentation in the MSDN library.

Applies to

Продукт Версії
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1