InterfaceTypeAttribute Class
Indicates whether a managed interface is dual, dispatch-only, or IUnknown-only when exposed to COM.
For a list of all members of this type, see InterfaceTypeAttribute Members.
System.Object
System.Attribute
System.Runtime.InteropServices.InterfaceTypeAttribute
[Visual Basic] <AttributeUsage(AttributeTargets.Interface)> NotInheritable Public Class InterfaceTypeAttribute Inherits Attribute [C#] [AttributeUsage(AttributeTargets.Interface)] public sealed class InterfaceTypeAttribute : Attribute [C++] [AttributeUsage(AttributeTargets::Interface)] public __gc __sealed class InterfaceTypeAttribute : public Attribute [JScript] public AttributeUsage(AttributeTargets.Interface) class InterfaceTypeAttribute extends Attribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
You can apply this attribute to interfaces.
By default, the Type Library Exporter (Tlbexp.exe) exposes a managed interface to COM as a dual interface, giving you the flexibility of late binding or the performance of early binding. The ComInterfaceType enumeration enables you to override the default behavior and specify late binding only or early binding only. For example, you can apply InterfaceType (ComInterfaceType.InterfaceIsIDispatch) to an interface to produce metadata to restrict callers to late binding only. Although interfaces that derive from the IDispatch interface are often dual, the InterfaceIsIDispatch enumeration member allows only late-bound calls to the interface methods. This attribute has no effect on the managed view of the interface. For additional information on how interfaces are exposed to COM, see Exported Type Conversion.
The Type Library Importer (Tlbimp.exe) also applies this attribute to imported, nondual interfaces; it applies the appropriate enumeration member to indicate that the interface is dispatch-only or IUnknown-only.
Example
The following example shows how InterfaceTypeAttribute controls how the interface is exposed to COM.
[Visual Basic] Imports System.Runtime.InteropServices 'Interface is exposed to COM as dual. Interface IMyInterface1 'Insert code here. End Interface 'Interface is exposed to COM as IDispatch. <InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _ Interface IMyInterface2 'Insert code here. End Interface [C#] using System.Runtime.InteropServices; //Interface is exposed to COM as dual. interface IMyInterface1 { //Insert code here. } //Interface is exposed to COM as IDispatch. [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] interface IMyInterface2 { //Insert code here. } [C++] using namespace System::Runtime::InteropServices; //Interface is exposed to COM as dual. __gc __interface IMyInterface1 { //Insert code here. }; //Interface is exposed to COM as IDispatch. [InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIDispatch)] __gc __interface IMyInterface2 { //Insert code here. }; [JScript] import System.Runtime.InteropServices //Interface will be exposed to COM as dual. interface IMyInterface1{ // ... } //Interface will be exposed to COM as IDispatch. public InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch) interface IMyInterface2{ // ... }
Requirements
Namespace: System.Runtime.InteropServices
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: Mscorlib (in Mscorlib.dll)
See Also
InterfaceTypeAttribute Members | System.Runtime.InteropServices Namespace | ComInterfaceType | Type Library Exporter (Tlbexp.exe) | Type Library Importer (Tlbimp.exe)