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í.
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
- Atributy
Pole
AutoDispatch | 1 | Označuje, že třída podporuje pouze pozdní vazbu pro klienty COM. A 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í |
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
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 |
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é
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro