ClassInterfaceType 列挙型

定義

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

public enum class ClassInterfaceType
public enum ClassInterfaceType
[System.Serializable]
public enum ClassInterfaceType
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ClassInterfaceType
type ClassInterfaceType = 
[<System.Serializable>]
type ClassInterfaceType = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ClassInterfaceType = 
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 から使用できます。

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;
    }
};
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; }
}
Imports 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 Sub New()

    End Sub

    Public Function Add(ByVal x As Int32, ByVal y As Int32) As Int32
        Return x + y

    End Function
End Class
' 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
    Implements IComparable

    Public Sub New()

    End Sub

    Function CompareTo(ByVal o As [Object]) As Int32 Implements IComparable.CompareTo
        Return 0

    End Function 'IComparable.CompareTo
End Class

注釈

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

適用対象

こちらもご覧ください