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
属性

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

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

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

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

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

コンストラクター

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)

適用対象

こちらもご覧ください