ClassInterfaceType Výčet
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
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
- Atributy
Pole
| Name | Hodnota | Description |
|---|---|---|
| None | 0 | Označuje, že pro třídu není generováno žádné rozhraní třídy. Pokud nejsou implementována žádná rozhraní explicitně, třída může poskytovat pouze pozdní přístup prostřednictvím
Tlbexp.exe (exportér knihovny typů) zveřejňuje první veřejné rozhraní com-visible implementované třídou jako výchozí rozhraní třídy coclass. V .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 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 zpět). Tlbexp.exe zpřístupňuje |
| AutoDispatch | 1 | Označuje, že třída podporuje pouze pozdní vazbu pro klienty MODELU COM. Třída 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 modelu COM. Informace o typu jsou vytvořeny pro rozhraní třídy a publikovány v knihovně typů. Použití |
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 .