ClassInterfaceType 枚举

定义

标识为某个类生成的类接口的类型。Identifies the type of class interface that is generated for a class.

public enum class ClassInterfaceType
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum ClassInterfaceType
type ClassInterfaceType = 
Public Enum ClassInterfaceType
继承
ClassInterfaceType
属性

字段

AutoDispatch 1

指示该类只支持 COM 客户端的后期绑定。Indicates that the class only supports late binding for COM clients. 在请求时,该类的 dispinterface 会自动向 COM 客户端公开。A dispinterface for the class is automatically exposed to COM clients on request. Tlbexp.exe(类型库导出程序) 生成的类型库不包含 dispinterface 的类型信息,以防止客户端缓存接口的 DISPID。The type library produced by Tlbexp.exe (Type Library Exporter) does not contain type information for the dispinterface in order to prevent clients from caching the DISPIDs of the interface. 由于客户端只能后期绑定到接口,因此 dispinterface 不会出现 ClassInterfaceAttribute 中所述的版本控制问题。The dispinterface does not exhibit the versioning problems described in ClassInterfaceAttribute because clients can only late-bind to the interface.

这是 ClassInterfaceAttribute 的默认设置。This is the default setting for ClassInterfaceAttribute.

AutoDual 2

指示自动为类生成双重类接口并向 COM 公开。Indicates that a dual class interface is automatically generated for the class and exposed to COM. 为该类接口生成类型信息并在类型库中发布。Type information is produced for the class interface and published in the type library. 由于 ClassInterfaceAttribute 中描述的版本控制方面的限制,极力建议不要使用 AutoDualUsing AutoDual is strongly discouraged because of the versioning limitations described in ClassInterfaceAttribute.

None 0

指示不为类生成类接口。Indicates that no class interface is generated for the class. 如果未显式实现任何接口,则该类只能通过 IDispatch 接口提供后期绑定访问。If no interfaces are implemented explicitly, the class can only provide late-bound access through the IDispatch interface. 这是 ClassInterfaceAttribute 的推荐设置。This is the recommended setting for ClassInterfaceAttribute. 要通过由类显式实现的接口公开功能,唯一的方法是使用 ClassInterfaceType.NoneUsing ClassInterfaceType.None is the only way to expose functionality through interfaces implemented explicitly by the class.

示例

此示例演示如何将应用ClassInterfaceAttribute到类型, 并ClassInterfaceType设置。This example shows how to apply the ClassInterfaceAttribute to a type, setting the ClassInterfaceType. 以这种方式定义的类可用于非托管 COM。Classes defined this way can be used from unmanaged COM.

using namespace System;
using namespace System::Runtime::InteropServices;

// Have the CLR expose a class interface (derived from IDispatch)
// for this type. COM clients can call the  members of this
// class using the Invoke method from the IDispatch interface.
[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class AClassUsableViaCOM
{
public:
    AClassUsableViaCOM() 
    { 
    }

public:
    int Add(int x, int y)
    {
        return x + y;
    }
};

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using
// the methods from the IComparable interface.
[ClassInterface(ClassInterfaceType::None)]
public ref class AnotherClassUsableViaCOM : public IComparable
{
public:
    AnotherClassUsableViaCOM() 
    { 
    }

    virtual int CompareTo(Object^ o) = IComparable::CompareTo
    {
        return 0;
    }
};
using System;
using System.Runtime.InteropServices;

// Have the CLR expose a class interface (derived from IDispatch) for this type.
// COM clients can call the  members of this class using the Invoke method from the IDispatch interface.
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AClassUsableViaCOM
{
    public AClassUsableViaCOM() { }

    public Int32 Add(Int32 x, Int32 y) { return x + y; }
}

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using the methods from the IComparable interface.
[ClassInterface(ClassInterfaceType.None)]
public class AnotherClassUsableViaCOM : IComparable
{
    public AnotherClassUsableViaCOM() { }

    Int32 IComparable.CompareTo(Object o) { return 0; }
}
Imports System.Runtime.InteropServices


' Have the CLR expose a class interface (derived from IDispatch) for this type.
' COM clients can call the  members of this class using the Invoke method from the IDispatch interface.
<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class AClassUsableViaCOM

    Public Sub New()

    End Sub

    Public Function Add(ByVal x As Int32, ByVal y As Int32) As Int32
        Return x + y

    End Function
End Class
' The CLR does not expose a class interface for this type.
' COM clients can call the members of this class using the methods from the IComparable interface.
<ClassInterface(ClassInterfaceType.None)> _
Public Class AnotherClassUsableViaCOM
    Implements IComparable

    Public Sub New()

    End Sub

    Function CompareTo(ByVal o As [Object]) As Int32 Implements IComparable.CompareTo
        Return 0

    End Function 'IComparable.CompareTo
End Class

注解

此枚举与ClassInterfaceAttribute属性一起使用。This enumeration is used in conjunction with the ClassInterfaceAttribute attribute.

适用于

另请参阅