ClassInterfaceAttribute クラス

定義

インターフェイスがまったく生成された場合に、COM に公開されるクラスに対して生成されるクラス インターフェイスの型を示します。

public ref class ClassInterfaceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)]
public sealed class ClassInterfaceAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ClassInterfaceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)>]
type ClassInterfaceAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ClassInterfaceAttribute = class
    inherit Attribute
Public NotInheritable Class ClassInterfaceAttribute
Inherits Attribute
継承
ClassInterfaceAttribute
属性

次の例は、MyClassIDispatch インターフェイスを生成するClassInterfaceTypeAutoDispatchClassInterfaceAttributeを適用する方法を示しています。

using namespace System::Runtime::InteropServices;

[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class MyClass
{
public:
   MyClass(){}

};
using System.Runtime.InteropServices;

[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass
{
   public MyClass() {}
}
Imports System.Runtime.InteropServices

<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class SampleClass    
    ' Insert class members here.
End Class

注釈

この属性は、アセンブリまたはクラスに適用できます。

この属性は、タイプ ライブラリ エクスポーター (Tlbexp.exe) が属性付きクラスのクラス インターフェイスを自動的に生成するかどうかを制御します。 クラス インターフェイスはクラス自体と同じ名前を持ちますが、名前の先頭にはアンダースコアが付きます。 公開されると、クラス インターフェイスには、基底クラスから継承されたメンバーを含む、マネージド クラスのすべての publicstatic 以外のメンバーが含まれます。 マネージド クラスはクラス インターフェイスにアクセスできず、クラス メンバーに直接アクセスできるため、必要はありません。 Tlbexp.exe は、クラス インターフェイスの一意のインターフェイス識別子 (IID) を生成します。

クラス インターフェイスには、デュアル インターフェイスまたはディスパッチ専用インターフェイスを使用できます。 必要に応じて、クラス インターフェイスの生成を抑制し、代わりにカスタム インターフェイスを提供できます。 クラス インターフェイスを公開または抑制するには、 System.Runtime.InteropServices.ClassInterfaceType 列挙メンバーを指定します。 ClassInterfaceAttributeをアセンブリに適用する場合、個々のクラスが独自の属性で設定をオーバーライドしない限り、属性はアセンブリ内のすべてのクラスに関連します。

クラス インターフェイスでは、各クラスのインターフェイスを明示的に定義するタスクは不要ですが、実稼働アプリケーションでのインターフェイスの使用は強くお勧めしません。 デュアル クラス インターフェイスを使用すると、クラスの進化に合わせて変更される可能性がある特定のインターフェイス レイアウトにクライアントをバインドできます。 たとえば、COM クライアントにクラス インターフェイスを公開するマネージド クラスを考えてみましょう。 クラスの最初のバージョンには、 North および Southメソッドが含まれています。 アンマネージ クライアントはクラス インターフェイスにバインドできます。このインターフェイスは、クラス インターフェイスの最初のメソッドとして North を提供し、メソッドは 2 番目のメソッドとして South します。 次に、メソッドNorthSouthの間に新しいメソッドEastが挿入されたクラスの次のバージョンについて考えます。 古いクラス インターフェイスを介して新しいクラスにバインドしようとするアンマネージド クライアントは、メソッド Southを呼び出そうとしたときにメソッド Eastを呼び出します。これは、インターフェイス内でのメソッドの配置が変更されたためです。 さらに、基底クラスのレイアウトを変更すると、すべての派生クラスのクラス インターフェイスのレイアウトにも影響します。 クラスに直接バインドされるマネージド クライアントでは、同じバージョン管理の問題は発生しません。 クラス インターフェイスの使用に関する具体的なガイドラインについては、 COM 呼び出し可能ラッパーを参照してください。

Tlbimp.exe (タイプ ライブラリ インポーター) は、インポートされたクラスClassInterfaceType.None列挙メンバーに常に適用され、既存の COM クラスがマネージド インターフェイスを公開しないことを示します。

コンストラクター

名前 説明
ClassInterfaceAttribute(ClassInterfaceType)

指定したClassInterfaceAttribute列挙メンバーを使用して、ClassInterfaceType クラスの新しいインスタンスを初期化します。

ClassInterfaceAttribute(Int16)

指定したClassInterfaceAttribute列挙値を使用して、ClassInterfaceType クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)
Value

クラスに対して生成する必要があるインターフェイスの種類を記述する ClassInterfaceType 値を取得します。

メソッド

名前 説明
Equals(Object)

このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください