ClassInterfaceType Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Identifies the type of class interface that is generated for a class.
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
- Inheritance
- Attributes
Fields
Name | Value | Description |
---|---|---|
None | 0 | 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
Tlbexp.exe (Type Library Exporter) exposes the first public, COM-visible interface implemented by the class as the default interface of the coclass. In .NET Framework 2.0 and later versions, 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 |
AutoDispatch | 1 | Indicates that the class only supports late binding for COM clients. A This is the default setting for ClassInterfaceAttribute. |
AutoDual | 2 | 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 |
Examples
This example shows how to apply the ClassInterfaceAttribute to a type, setting the ClassInterfaceType. 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
Remarks
This enumeration is used in conjunction with the ClassInterfaceAttribute attribute.