ClassInterfaceAttributeとは? わかりやすく解説

ClassInterfaceAttribute クラス

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

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class,
 Inherited:=False)> _
Public NotInheritable Class
 ClassInterfaceAttribute
    Inherits Attribute
Dim instance As ClassInterfaceAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false)]
 
public sealed class ClassInterfaceAttribute
 : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class, Inherited=false)]
 
public ref class ClassInterfaceAttribute sealed
 : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class,
 Inherited=false) */ 
public final class ClassInterfaceAttribute
 extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false)
 
public final class ClassInterfaceAttribute
 extends Attribute
解説解説

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

この属性は、タイプ ライブラリ エクスポータ (Tlbexp.exe) が属性付きのクラスに対してクラス インターフェイスを自動的に生成するかどうかを制御します。クラス インターフェイスの名前は、クラス自体と同じですが、プリフィックスとしてアンダースコアが付きます。公開されると、クラス インターフェイスには、基本クラスから継承したメンバのほか、マネージ クラスのすべての public メンバと非 static メンバが含まれます。マネージ クラスからクラス インターフェイスにはアクセスできませんが、マネージ クラスの場合はメンバに直接アクセスできるため、その必要はありません。Tlbexp.exe は、クラス インターフェイスに対して一意のインターフェイス ID (IID) を生成します。

クラス インターフェイスには、デュアル インターフェイスとディスパッチ専用インターフェイスがあります。必要があれば、クラス インターフェイスを生成せずに、代わりにカスタム インターフェイスを提供することもできます。クラス インターフェイスを公開するかどうかは、System.Runtime.InteropServices.ClassInterfaceType 列挙体メンバを使用して指定します。ClassInterfaceAttribute をアセンブリに適用した場合、個々のクラスがそれぞれの属性で設定をオーバーライドしていない限り、この属性はアセンブリ内のすべてのクラスに適用されます。

クラス インターフェイスを使用すると、クラスごとにインターフェイスを明示的に定義する必要がなくなりますが、本運用のアプリケーションでこれを使用することはできる限り避けてください。デュアル クラス インターフェイスは、クライアントが、クラスの変化による影響を受けやすい特定のインターフェイス レイアウトにバインドできるようにします。たとえば、クラス インターフェイスを COM クライアントに公開するマネージ クラスについて考えてみます。最初のバージョンのクラスは、North メソッドと South メソッドを含んでいます。アンマネージ クライアントは、1 番目のメソッドとして North、2 番目のメソッドとして South を提供するクラス インターフェイスにバインドできます。次に、メソッド North と South の間に新しい East メソッドを挿入した、同じクラスの次のバージョンについて考えます。アンマネージ クライアントが以前のクラス インターフェイスを通じて新しいクラスにバインドしようとした場合は、インターフェイス内のメソッドの位置が変更されてしまっているため、South メソッドを呼び出そうとしたときに、East メソッドが呼び出されてしまうことになります。さらに、基本クラスのレイアウトを変更すると、すべての派生クラスのクラス インターフェイスのレイアウトにも影響があります。クラスに直接バインドするマネージ クライアントでは、このようなバージョン問題が発生しません。クラス インターフェイスの使用に関するガイドラインについては、「クラス インターフェイスの概要」を参照してください。

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

使用例使用例

ClassInterfaceType に AutoDispatch を指定して ClassInterfaceAttribute を適用し、MyClass の IDispatch インターフェイスを生成する例を次に示します。

Imports System.Runtime.InteropServices

<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class SampleClass    
    ' Insert class members here.
End Class
using System.Runtime.InteropServices;

[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass
{
   public MyClass() {}
}
using namespace System::Runtime::InteropServices;

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

};

import System.Runtime.InteropServices.*;

/** @attribute ClassInterface(ClassInterfaceType.AutoDispatch)
 */
public class MyClass
{
    public MyClass()
    {
    } //MyClass
} //MyClass 
継承階層継承階層
System.Object
   System.Attribute
    System.Runtime.InteropServices.ClassInterfaceAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClassInterfaceAttribute メンバ
System.Runtime.InteropServices 名前空間
ClassInterfaceType
その他の技術情報
タイプ ライブラリ エクスポータ (Tlbexp.exe)
タイプ ライブラリ インポータ (Tlbimp.exe)

ClassInterfaceAttribute コンストラクタ (ClassInterfaceType)

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

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    classInterfaceType As ClassInterfaceType _
)
Dim classInterfaceType As ClassInterfaceType

Dim instance As New ClassInterfaceAttribute(classInterfaceType)
public ClassInterfaceAttribute (
    ClassInterfaceType classInterfaceType
)
public:
ClassInterfaceAttribute (
    ClassInterfaceType classInterfaceType
)
public ClassInterfaceAttribute (
    ClassInterfaceType classInterfaceType
)
public function ClassInterfaceAttribute (
    classInterfaceType : ClassInterfaceType
)

パラメータ

classInterfaceType

クラスに対して生成するインターフェイスの型について説明する ClassInterfaceType 値の 1 つ。

解説解説

エラーを招きにくく、読みやすいコードにするためには、常にこのコンストラクタを使用してください。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClassInterfaceAttribute クラス
ClassInterfaceAttribute メンバ
System.Runtime.InteropServices 名前空間

ClassInterfaceAttribute コンストラクタ

ClassInterfaceAttribute クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
ClassInterfaceAttribute (ClassInterfaceType) 指定した ClassInterfaceType 列挙体メンバを使用して、ClassInterfaceAttribute クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

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

.NET Compact Framework によってサポートされています。

参照参照

関連項目

ClassInterfaceAttribute クラス
ClassInterfaceAttribute メンバ
System.Runtime.InteropServices 名前空間

ClassInterfaceAttribute コンストラクタ (Int16)

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

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    classInterfaceType As Short _
)
Dim classInterfaceType As Short

Dim instance As New ClassInterfaceAttribute(classInterfaceType)
public ClassInterfaceAttribute (
    short classInterfaceType
)
public:
ClassInterfaceAttribute (
    short classInterfaceType
)
public ClassInterfaceAttribute (
    short classInterfaceType
)
public function ClassInterfaceAttribute (
    classInterfaceType : short
)

パラメータ

classInterfaceType

クラスに対して生成するインターフェイスの型について説明します。

解説解説

このコンストラクタは、ClassInterfaceType 列挙体の各メンバを表す、基になる 16 ビット符号付き整数値を受け取ります。タイプ ライブラリ インポータ (Tlbimp.exe) は、このコンストラクタを使用します。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClassInterfaceAttribute クラス
ClassInterfaceAttribute メンバ
System.Runtime.InteropServices 名前空間
ClassInterfaceType
その他の技術情報
タイプ ライブラリ インポータ (Tlbimp.exe)

ClassInterfaceAttribute プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

ClassInterfaceAttribute クラス
System.Runtime.InteropServices 名前空間
ClassInterfaceType

その他の技術情報

タイプ ライブラリ エクスポータ (Tlbexp.exe)
タイプ ライブラリ インポータ (Tlbimp.exe)

ClassInterfaceAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
参照参照

関連項目

ClassInterfaceAttribute クラス
System.Runtime.InteropServices 名前空間
ClassInterfaceType

その他の技術情報

タイプ ライブラリ エクスポータ (Tlbexp.exe)
タイプ ライブラリ インポータ (Tlbimp.exe)

ClassInterfaceAttribute メンバ

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

ClassInterfaceAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ClassInterfaceAttribute オーバーロードされます。 ClassInterfaceAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
参照参照

関連項目

ClassInterfaceAttribute クラス
System.Runtime.InteropServices 名前空間
ClassInterfaceType

その他の技術情報

タイプ ライブラリ エクスポータ (Tlbexp.exe)
タイプ ライブラリ インポータ (Tlbimp.exe)


このページでは「.NET Framework クラス ライブラリ リファレンス」からClassInterfaceAttributeを検索した結果を表示しています。
Weblioに収録されているすべての辞書からClassInterfaceAttributeを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からClassInterfaceAttribute を検索

英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ClassInterfaceAttribute」の関連用語

ClassInterfaceAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ClassInterfaceAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS