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

フィールド

名前 説明
None 0

クラスに対してクラス インターフェイスが生成されていないことを示します。 インターフェイスが明示的に実装されていない場合、クラスは IDispatch インターフェイス経由でのみ遅延バインディング アクセスを提供できます。 これは、 ClassInterfaceAttributeに推奨される設定です。 ClassInterfaceType.Noneを使用することは、クラスによって明示的に実装されたインターフェイスを介して機能を公開する唯一の方法です。

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

AutoDispatch 1

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

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

AutoDual 2

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

この例では、 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 属性と組み合わせて使用されます。

適用対象

こちらもご覧ください