ClassInterfaceType 列挙体とは? わかりやすく解説

ClassInterfaceType 列挙体

クラスに対して生成するクラス インターフェイスの型を識別します。

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

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration ClassInterfaceType
Dim instance As ClassInterfaceType
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum ClassInterfaceType
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class ClassInterfaceType
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum ClassInterfaceType
SerializableAttribute 
ComVisibleAttribute(true) 
public enum ClassInterfaceType
メンバメンバ
 メンバ名説明
AutoDispatchクラスが COM クライアントに対して遅延バインディングだけをサポートすることを示します。クラスのディスパッチ インターフェイスは、要求に応じて自動的に COM クライアントに公開されます。型 タイプ ライブラリ エクスポータ (Tlbexp.exe) によって生成されるタイプ ライブラリには、クライアントがこのディスパッチ インターフェイスの DISPID をキャッシュしないようにするために、そのインターフェイスの型情報は含まれません。クライアントがこのディスパッチ インターフェイスに対して実行できるのは遅延バインディングだけであるため、ClassInterfaceAttribute で説明したようなバージョン管理の問題は、このインターフェイスでは発生しません。 

これは、ClassInterfaceAttribute の既定の設定です。

AutoDualクラスに対してデュアル クラス インターフェイスを自動的に生成し、COM に公開することを示します。型情報は、クラス インターフェイスに対して作成され、タイプ ライブラリで公開されます。ClassInterfaceAttribute で説明したようなバージョン管理の制約があるため、AutoDual は使用しないことを強くお勧めします。 
.NET Compact Framework によるサポートNoneクラスに対してクラス インターフェイスを生成しないことを示します。インターフェイスを明示的に実装していないクラスには、IDispatch インターフェイスを通じた遅延バインディングによってしかアクセスできません。これは、ClassInterfaceAttribute の推奨値です。このクラスが明示的に実装しているインターフェイスを通じて機能を公開するには、ClassInterfaceType.None の使用が唯一の方法です。 

タイプ ライブラリ エクスポータ (Tlbexp.exe) は、クラスが 1 番目に実装しているパブリックで COM 参照可能なインターフェイスを、コクラスの既定のインターフェイスとして公開します。.NET Framework Version 2.0 からは、ComDefaultInterfaceAttribute 属性を使用して、COM に公開される既定のインターフェイスを指定できます。クラスが実装しているインターフェイスがない場合は、基本クラスが 1 番目に実装しているパブリックで COM 参照可能なインターフェイスが既定のインターフェイスとなります。このとき、最後に派生した基本クラスから逆順に検索されます。クラスもその基本クラスもインターフェイスを実装していない場合、Tlbexp.exe は _Object を既定のインターフェイスとして公開します。

解説解説

この列挙体は、ClassInterfaceAttribute 属性と組み合わせて使用します。

使用例使用例

ClassInterfaceAttribute を型に適用し、ClassInterfaceType を設定する例を次に示します。この方法で定義されたクラスは、アンマネージ COM から使用できます。

using System;
using System.Runtime.InteropServices;

// Have the CLR expose a class interface (derived from IDispatch) for
 this type.
// COM clients can call the  members of this class using the Invoke
 method from the IDispatch interface.
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AClassUsableViaCOM
{
    public AClassUsableViaCOM() { }

    public Int32 Add(Int32 x, Int32 y) { return
 x + y; }
}

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using the methods
 from the IComparable interface.
[ClassInterface(ClassInterfaceType.None)]
public class AnotherClassUsableViaCOM : IComparable
{
    public AnotherClassUsableViaCOM() { }

    Int32 IComparable.CompareTo(Object o) { return 0; }
}
using namespace System;
using namespace System::Runtime::InteropServices;

// Have the CLR expose a class interface (derived from IDispatch)
// for this type. COM clients can call the  members of this
// class using the Invoke method from the IDispatch interface.
[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class AClassUsableViaCOM
{
public:
    AClassUsableViaCOM() 
    { 
    }

public:
    int Add(int x, int y)
    {
        return x + y;
    }
};

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using
// the methods from the IComparable interface.
[ClassInterface(ClassInterfaceType::None)]
public ref class AnotherClassUsableViaCOM :
 public IComparable
{
public:
    AnotherClassUsableViaCOM() 
    { 
    }

    virtual int CompareTo(Object^ o) = IComparable::CompareTo
    {
        return 0;
    }
};
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Runtime.InteropServices 名前空間
その他の技術情報
タイプ ライブラリ エクスポータ (Tlbexp.exe)



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「ClassInterfaceType 列挙体」の関連用語

ClassInterfaceType 列挙体のお隣キーワード
検索ランキング

   

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



ClassInterfaceType 列挙体のページの著作権

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

©2026 GRAS Group, Inc.RSS