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)에서 생성된 형식 라이브러리는 클라이언트가 인터페이스의 DISPID를 캐시하지 못하게 하기 위해 dispinterface에 대한 형식 정보를 포함하지 않습니다. 클라이언트는 런타임에만 인터페이스에 바인딩할 수 있으므로 dispinterface에는 ClassInterfaceAttribute에서 설명한 버전 관리 문제가 나타내지 않습니다.

이것은 ClassInterfaceAttribute의 기본 설정입니다.

AutoDual 2

이중 클래스 인터페이스가 클래스에 대해 자동으로 생성되고 COM에 노출됨을 나타냅니다. 클래스 인터페이스에 대해 형식 정보가 생성되어 형식 라이브러리에 게시됩니다. ClassInterfaceAttribute에서 설명하는 것처럼 버전 관리 제한 때문에 AutoDual은 사용하지 않아야 합니다.

None 0

해당 클래스에 대해 클래스 인터페이스가 생성되지 않음을 나타냅니다. 명시적으로 구현되는 인터페이스가 없으면 런타임에 바인딩될 때 IDispatch 인터페이스를 통해서만 클래스에 액세스할 수 있습니다. 이것이 ClassInterfaceAttribute에 대해 권장되는 설정입니다. 클래스에서 명시적으로 구현한 인터페이스를 통해 기능을 노출시키는 유일한 방법은 ClassInterfaceType.None을 사용하는 것입니다.

Tlbexp.exe(형식 라이브러리 내보내기)는 coclass의 기본 인터페이스로 클래스에 의해 구현된 첫 번째 퍼블릭 COM에 노출 인터페이스를 노출합니다. .NET Framework 2.0 이상 버전에서는 ComDefaultInterfaceAttribute 특성을 사용하여 COM에 노출되는 기본 인터페이스를 지정할 수 있습니다. 클래스가 인터페이스를 구현하지 않는 경우 기본 클래스에 의해 구현된 첫 번째 퍼블릭 COM에 노출 인터페이스가 기본 인터페이스가 됩니다(가장 최근에 파생된 기본 클래스로 시작하여 뒤로 작업). 클래스 또는 기본 클래스가 인터페이스를 구현하지 않는 경우 Tlbexp.exe는 기본 인터페이스로 _Object를 노출합니다.

예제

이 예제에서는 형식ClassInterfaceTypeClassInterfaceAttribute 적용하고 . 이러한 방식으로 정의된 클래스는 관리되지 않는 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 사용됩니다.

적용 대상

추가 정보