次の方法で共有


InterfaceTypeAttribute クラス

COM への公開時に、マネージ インターフェイスがデュアル、ディスパッチ専用、または IUnknown 専用のいずれであるかを示します。

この型のすべてのメンバの一覧については、InterfaceTypeAttribute メンバ を参照してください。

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

<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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

この属性は、インターフェイスに適用できます。

タイプ ライブラリ エクスポータ (Tlbexp.exe) は既定では、マネージ インターフェイスをデュアル インターフェイスとして COM に公開します。これによって、遅延バインディングの柔軟性と事前バインディングのパフォーマンスを得ることができます。 ComInterfaceType 列挙体を使用すると、既定の動作をオーバーライドして、遅延バインディングだけ、または事前バインディングだけを指定できます。たとえば、 InterfaceType (ComInterfaceType.InterfaceIsIDispatch) をインターフェイスに適用すると、呼び出し元を遅延バインディングだけに制限するメタデータを生成できます。 IDispatch インターフェイスから継承したインターフェイスの多くはデュアル インターフェイスですが、 InterfaceIsIDispatch 列挙体メンバを使用すると、インターフェイスのメソッドに対して遅延バインディング呼び出しだけを許可できます。この属性は、インターフェイスのマネージ ビューには影響を与えません。インターフェイスを COM に公開する方法の詳細については、「 エクスポート時の型の変換 」を参照してください。

タイプ ライブラリ インポータ (Tlbimp.exe) はまた、インポートされた非デュアル インターフェイスにこの属性を適用します。適切な列挙体メンバを適用することによって、インターフェイスがディスパッチ専用か IUnknown 専用かを示します。

使用例

InterfaceTypeAttribute でインターフェイスを COM に公開する方法を制御する方法を次の例に示します。

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

必要条件

名前空間: System.Runtime.InteropServices

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

InterfaceTypeAttribute メンバ | System.Runtime.InteropServices 名前空間 | ComInterfaceType | タイプ ライブラリ エクスポータ (Tlbexp.exe) | タイプ ライブラリ インポータ (Tlbimp.exe)