Export (0) Print
Expand All

InterfaceTypeAttribute Class

Indicates whether a managed interface is dual, dispatch-only, or IUnknown -only when exposed to COM.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets.Interface, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class InterfaceTypeAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Interface, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class InterfaceTypeAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Interface, Inherited=false) 
ComVisibleAttribute(true) 
public final class InterfaceTypeAttribute extends Attribute

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.

The following example shows how InterfaceTypeAttribute controls how the interface is exposed to COM.

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

import System.Runtime.InteropServices.*;

//Interface is exposed to COM as dual.
interface IMyInterface1
{
    //Insert code here.
} //IMyInterface1

//Interface is exposed to COM as IDispatch.
/** @attribute InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)
 */
interface IMyInterface2
{
    //Insert code here.
} //IMyInterface2

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{
    // ...
}

System.Object
   System.Attribute
    System.Runtime.InteropServices.InterfaceTypeAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft