ClassInterfaceType Wyliczenie

Definicja

Określa typ interfejsu klasy, który jest generowany dla klasy.

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
Dziedziczenie
ClassInterfaceType
Atrybuty

Pola

AutoDispatch 1

Wskazuje, że klasa obsługuje tylko późne powiązanie dla klientów COM. Klasa A dispinterface jest automatycznie widoczna dla klientów COM na żądanie. Biblioteka typów utworzona przez Tlbexp.exe (eksporter biblioteki typów) nie zawiera informacji o typie dla dispinterface elementu , aby uniemożliwić klientom buforowanie identyfikatorów DISPID interfejsu. Element dispinterface nie wykazuje problemów z przechowywaniem wersji opisanych w temacie ClassInterfaceAttribute , ponieważ klienci mogą powiązać tylko późno z interfejsem.

Jest to ustawienie domyślne dla elementu ClassInterfaceAttribute.

AutoDual 2

Wskazuje, że interfejs podwójnej klasy jest generowany automatycznie dla klasy i uwidoczniony w modelu COM. Informacje o typie są tworzone dla interfejsu klasy i publikowane w bibliotece typów. Używanie AutoDual jest zdecydowanie odradzane z powodu ograniczeń przechowywania wersji opisanych w temacie ClassInterfaceAttribute.

None 0

Wskazuje, że dla klasy nie jest generowany żaden interfejs klasy. Jeśli interfejsy nie są implementowane jawnie, klasa może zapewnić tylko ograniczony do końca dostęp za pośrednictwem interfejsu IDispatch . Jest to zalecane ustawienie dla programu ClassInterfaceAttribute. Użycie ClassInterfaceType.None to jedyny sposób uwidaczniania funkcji za pośrednictwem interfejsów implementowanych jawnie przez klasę.

Tlbexp.exe (eksporter biblioteki typów) uwidacznia pierwszy publiczny, widoczny dla modelu COM interfejs zaimplementowany przez klasę jako domyślny interfejs coclass. W .NET Framework wersji 2.0 i nowszych można określić domyślny interfejs uwidoczniony dla modelu COM przy użyciu atrybutu ComDefaultInterfaceAttribute . Jeśli klasa nie implementuje żadnych interfejsów, pierwszy publiczny interfejs widoczny dla modelu COM implementowany przez klasę bazową staje się interfejsem domyślnym (począwszy od ostatnio pochodnej klasy bazowej i pracy wstecz). Tlbexp.exe uwidacznia _Object jako interfejs domyślny, jeśli ani klasa, ani jej klasy bazowe nie implementują interfejsów.

Przykłady

W tym przykładzie pokazano, jak zastosować element ClassInterfaceAttribute do typu, ustawiając wartość ClassInterfaceType. Klasy zdefiniowane w ten sposób mogą być używane z niezarządzanego modelu 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

Uwagi

To wyliczenie jest używane w połączeniu z atrybutem ClassInterfaceAttribute .

Dotyczy

Zobacz też