英語で読む

次の方法で共有


ClassInterfaceType 列挙型

定義

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

C#
public enum ClassInterfaceType
C#
[System.Serializable]
public enum ClassInterfaceType
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ClassInterfaceType
継承
ClassInterfaceType
属性

フィールド

名前 説明
AutoDispatch 1

クラスが COM クライアントに対して遅延バインディングだけをサポートすることを示します。 クラスの dispinterface は、要求に応じて自動的に COM クライアントに公開されます。 Tlbexp.exe (Type Library Exporter) によって生成されるタイプ ライブラリには、dispinterface の型情報は含まれません。これは、クライアントがこのインターフェイスの DISPID をキャッシュしないようにするためです。 クライアントがこの dispinterface に対して実行できるのは遅延バインディングだけであるため、ClassInterfaceAttribute に示されているバージョン管理の問題は、このインターフェイスでは発生しません。

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

AutoDual 2

クラスに対してデュアル クラス インターフェイスを自動的に生成し、COM に公開することを示します。 型情報は、クラス インターフェイスに対して作成され、タイプ ライブラリで公開されます。 ClassInterfaceAttribute で説明したようなバージョン管理の制約があるため、AutoDual は使用しないことを強くお勧めします。

None 0

クラスに対してクラス インターフェイスを生成しないことを示します。 インターフェイスを明示的に実装していないクラスには、IDispatch インターフェイスを通じた遅延バインディングによってしかアクセスできません。 これは、ClassInterfaceAttribute の推奨値です。 このクラスが明示的に実装しているインターフェイスを通じて機能を公開するには、ClassInterfaceType.None の使用が唯一の方法です。

Tlbexp.exe (タイプ ライブラリ エクスポーター) は、クラスがコクラスの既定のインターフェイスとして実装する、COM から参照できる最初のパブリック インターフェイスを公開します。 .NET Framework 2.0 以降のバージョンでは、ComDefaultInterfaceAttribute 属性を使用して、COM に公開される既定のインターフェイスを指定できます。 クラスがインターフェイスを実装していない場合は、基底クラスによって実装されている、COM から参照できる最初のパブリック インターフェイスが、既定のインターフェイスになります (最後に派生した基底クラスから開始します)。 Tlbexp.exe は、クラスもその基底クラスもインターフェイスを実装していない場合、既定のインターフェイスとして _Object を公開します。

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

C#
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; }
}

注釈

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

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

こちらもご覧ください