ClassInterfaceType 枚举

定义

标识为类生成的类接口的类型。

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

字段

名称 说明
None 0

指示没有为类生成类接口。 如果未显式实现接口,则类只能通过接口提供后期绑定访问 IDispatch 。 这是建议的 ClassInterfaceAttribute设置。 使用 ClassInterfaceType.None 是通过类显式实现的接口公开功能的唯一方法。

Tlbexp.exe(类型库导出程序) 公开由类实现的第一个公共 COM 可见接口作为 coclass 的默认接口。 在 .NET Framework 2.0 及更高版本中,可以使用 ComDefaultInterfaceAttribute 属性指定向 COM 公开的默认接口。 如果类不实现任何接口,则基类实现的第一个公共 COM 可见接口将成为默认接口(从最近派生的基类开始,向后工作)。 如果类及其基类均未实现接口,则 Tlbexp.exe 公开 _Object 为默认接口。

AutoDispatch 1

指示该类仅支持 COM 客户端的后期绑定。 类的 A dispinterface 在请求时自动向 COM 客户端公开。 Tlbexp.exe(类型库导出程序)生成的类型库不包含类型信息dispinterface,以防止客户端缓存接口的 DISPID。 由于客户端只能后期绑定到接口,因此 dispinterface 不会显示上述 ClassInterfaceAttribute 版本控制问题。

这是默认设置 ClassInterfaceAttribute

AutoDual 2

指示为类自动生成双类接口,并公开给 COM。 类型信息是为类接口生成的,并在类型库中发布。 由于上述ClassInterfaceAttribute版本控制限制,强烈建议不要使用AutoDual

示例

此示例演示如何将类型应用于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 特性结合使用。

适用于

另请参阅