ClassInterfaceType Výčet

Definice

Určuje typ rozhraní třídy, který je generován pro třídu.

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
Dědičnost
ClassInterfaceType
Atributy

Pole

AutoDispatch 1

Označuje, že třída podporuje pouze pozdní vazbu pro klienty COM. A dispinterface pro třídu je automaticky zpřístupněn klientům com na vyžádání. Knihovna typů vytvořená nástrojemTlbexp.exe (Type Library Exporter) neobsahuje informace o typu pro dispinterface objekt, aby se zabránilo klientům v ukládání dispidů rozhraní do mezipaměti. Nástroj dispinterface nevykazuje problémy správy verzí popsané v ClassInterfaceAttribute , protože klienti mohou s rozhraním vytvořit pouze pozdní vazbu.

Toto je výchozí nastavení pro ClassInterfaceAttribute.

AutoDual 2

Označuje, že rozhraní duální třídy je automaticky generováno pro třídu a vystaveno com. Informace o typu jsou vytvořeny pro rozhraní třídy a publikovány v knihovně typů. Použití AutoDual se důrazně nedoporučuje kvůli omezením správy verzí popsaným v ClassInterfaceAttributetématu .

None 0

Označuje, že pro třídu není generováno žádné rozhraní třídy. Pokud nejsou explicitně implementována žádná rozhraní, třída může poskytovat pouze pozdní přístup prostřednictvím IDispatch rozhraní. Toto je doporučené nastavení pro ClassInterfaceAttribute. Použití ClassInterfaceType.None je jediným způsobem, jak zpřístupnit funkce prostřednictvím rozhraní implementovaných explicitně třídou.

Tlbexp.exe (type library exportér) zveřejňuje první veřejné rozhraní viditelné pro com implementované třídou jako výchozí rozhraní coclass. V rozhraní .NET Framework 2.0 a novějších verzích můžete zadat výchozí rozhraní vystavené modelu COM pomocí atributu ComDefaultInterfaceAttribute . Pokud třída neimplementuje žádná rozhraní, stane se výchozím rozhraním (počínaje nejnovější odvozenou základní třídou a pracující zpětně) první veřejné rozhraní, které je vidět na modelu COM implementované základní třídou. Tlbexp.exe zpřístupňuje _Object jako výchozí rozhraní, pokud třída ani její základní třídy neimplementují rozhraní.

Příklady

Tento příklad ukazuje, jak použít ClassInterfaceAttribute na typ a nastavit .ClassInterfaceType Třídy definované tímto způsobem lze použít z nespravovaného 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

Poznámky

Tento výčet se používá ve spojení s atributem ClassInterfaceAttribute .

Platí pro

Viz také