ClassInterfaceType Výčet

Definice

Identifikuje typ rozhraní třídy, které je generováno 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 MODELU COM. Třída dispinterface je automaticky vystavena klientům modelu COM na vyžádání. Knihovna typů vytvořená Tlbexp.exe (exportérem knihovny typů) neobsahuje informace o typu, dispinterface aby se zabránilo klientům v ukládání identifikátorů DISPID rozhraní do mezipaměti. dispinterface Nevykazuje problémy s verzí popsanými v ClassInterfaceAttribute tom, že klienti můžou rozhraní svázat pouze pozdě.

Toto je výchozí nastavení pro ClassInterfaceAttribute.

AutoDual 2

Označuje, že pro třídu je automaticky generováno rozhraní duální třídy a vystaveno modelu 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ých 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 přístup pouze pozdě vázaný prostřednictvím IDispatch rozhraní. Toto je doporučené nastavení pro ClassInterfaceAttribute. Použití ClassInterfaceType.None je jediný způsob, jak zpřístupnit funkce prostřednictvím rozhraní implementovaných explicitně třídou.

Tlbexp.exe (exportér knihovny typů) zveřejňuje první veřejné rozhraní com-visible implementované třídou jako výchozí rozhraní coclass. V rozhraní .NET Framework 2.0 a novějších verzích můžete pomocí atributu ComDefaultInterfaceAttribute zadat výchozí rozhraní vystavené modelu COM. Pokud třída implementuje žádná rozhraní, první veřejné, com-viditelné rozhraní implementované základní třídou se stane výchozím rozhraním (počínaje nejnovější odvozenou základní třídou a práce dozadu). Tlbexp.exe zveřejňuje _Object jako výchozí rozhraní, pokud třída ani její základní třídy implementují rozhraní.

Příklady

Tento příklad ukazuje, jak použít typ ClassInterfaceAttribute , nastavení 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é