[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Identifies the type of class interface that is generated for a class.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration ClassInterfaceType
[SerializableAttribute] [ComVisibleAttribute(true)] public enum ClassInterfaceType
[SerializableAttribute] [ComVisibleAttribute(true)] public enum class ClassInterfaceType
[<SerializableAttribute>] [<ComVisibleAttribute(true)>] type ClassInterfaceType
| Member name | Description | |
|---|---|---|
|
None |
Indicates that no class interface is generated for the class. If no interfaces are implemented explicitly, the class can only provide late-bound access through the IDispatch interface. This is the recommended setting for ClassInterfaceAttribute. Using ClassInterfaceType.None is the only way to expose functionality through interfaces implemented explicitly by the class.
Tlbexp.exe (Type Library Exporter) exposes the first public, COM-visible interface implemented by the class as the default interface of the coclass. Beginning with the .NET Framework version 2.0, you can specify the default interface exposed to COM by using the ComDefaultInterfaceAttribute attribute. If the class implements no interfaces, the first public, COM-visible interface implemented by a base class becomes the default interface (starting with the most recently derived base class and working backward). Tlbexp.exe exposes _Object as the default interface if neither the class nor its base classes implement interfaces. |
|
AutoDispatch |
Indicates that the class only supports late binding for COM clients. A dispinterface for the class is automatically exposed to COM clients on request. 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. The dispinterface does not exhibit the versioning problems described in ClassInterfaceAttribute because clients can only late-bind to the interface.
This is the default setting for ClassInterfaceAttribute. |
|
AutoDual | 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. Using AutoDual is strongly discouraged because of the versioning limitations described in ClassInterfaceAttribute. |
This enumeration is used in conjunction with the ClassInterfaceAttribute attribute.
This example shows how to apply the ClassInterfaceAttribute to a type, setting the ClassInterfaceType. Classes defined this way can be used from unmanaged COM.
Imports System 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
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; } };
.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Portable Class Library
Supported in: Portable Class LibraryWindows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.