ClassInterfaceType 枚举

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

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration ClassInterfaceType
用法
Dim instance As ClassInterfaceType
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum ClassInterfaceType
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class ClassInterfaceType
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum ClassInterfaceType
SerializableAttribute 
ComVisibleAttribute(true) 
public enum ClassInterfaceType

成员

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

这是 ClassInterfaceAttribute 的默认设置。

AutoDual 指示自动为类生成双重类接口并向 COM 公开。为该类接口生成类型信息并在类型库中发布。由于 ClassInterfaceAttribute 中描述的版本控制方面的限制,极力建议不要使用 AutoDual。 
由 .NET Compact Framework 支持 None 指示不为类生成类接口。如果未显式实现任何接口,则该类将只通过 IDispatch 接口提供后期绑定访问。这是 ClassInterfaceAttribute 的推荐设置。要通过由类显式实现的接口来公开功能,唯一的方法是使用 ClassInterfaceType.None。 

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

备注

此枚举和 ClassInterfaceAttribute 属性一起使用。

示例

此示例显示如何将 ClassInterfaceAttribute 应用于一个类型,并设置 ClassInterfaceType。可以从非托管 COM 使用以这种方式定义的类。

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; }
}
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;
    }
};

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

System.Runtime.InteropServices 命名空间

其他资源

类型库导出程序 (Tlbexp.exe)