ClassInterfaceType 枚举  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
标识为类生成的类接口类型。
public enum class ClassInterfaceTypepublic enum ClassInterfaceType[System.Serializable]
public enum ClassInterfaceType[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ClassInterfaceTypetype ClassInterfaceType = [<System.Serializable>]
type ClassInterfaceType = [<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ClassInterfaceType = Public Enum ClassInterfaceType- 继承
- 属性
字段
| 名称 | 值 | 说明 | 
|---|---|---|
| AutoDispatch | 1 | 指示该类只支持 COM 客户端的后期绑定。 在请求时,该类的  这是 ClassInterfaceAttribute 的默认设置。 | 
| AutoDual | 2 | 指示自动为类生成双重类接口并向 COM 公开。 为该类接口生成类型信息并在类型库中发布。 由于 ClassInterfaceAttribute 中描述的版本控制方面的限制,极力建议不要使用  | 
| None | 0 | 指示不为类生成类接口。 如果未显式实现任何接口,则该类只能通过  
              Tlbexp.exe (类型库导出程序)公开作为组件类的默认接口由类实现的第一个公共、COM 可见接口。 在 .NET Framework 2.0 及更高版本中,可以使用 ComDefaultInterfaceAttribute 属性指定向 COM 公开的默认接口。 如果类未实现任何接口,则由基类实现的第一个公共的、COM 可见的接口将成为默认接口(从最近派生的基类开始,以此倒推)。 如果类及其基类都不实现接口,则 Tlbexp.exe 会将  | 
示例
此示例演示如何将 应用于 ClassInterfaceAttribute 类型,并 ClassInterfaceType设置 。 以这种方式定义的类可以从非托管 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 属性结合使用。