ClassInterfaceType Enumerazione
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Identifica il tipo di interfaccia di classe generata per una classe.
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
- Ereditarietà
- Attributi
Campi
| Nome | Valore | Descrizione |
|---|---|---|
| None | 0 | Indica che per la classe non viene generata alcuna interfaccia di classe. Se non vengono implementate interfacce in modo esplicito, la classe può fornire solo l'accesso ad associazione tardiva tramite l'interfaccia
Tlbexp.exe (Utilità di esportazione della libreria dei tipi) espone la prima interfaccia visibile COM pubblica implementata dalla classe come interfaccia predefinita della coclasse. In .NET Framework 2.0 e versioni successive è possibile specificare l'interfaccia predefinita esposta a COM usando l'attributo ComDefaultInterfaceAttribute. Se la classe non implementa interfacce, la prima interfaccia pubblica visibile com implementata da una classe di base diventa l'interfaccia predefinita ,a partire dalla classe base derivata più di recente e dall'uso indietro. Tlbexp.exe espone |
| AutoDispatch | 1 | Indica che la classe supporta solo l'associazione tardiva per i client COM. Un Questa è l'impostazione predefinita per ClassInterfaceAttribute. |
| AutoDual | 2 | Indica che viene generata automaticamente un'interfaccia dual class per la classe ed esposta a COM. Le informazioni sui tipi vengono generate per l'interfaccia della classe e pubblicate nella libreria dei tipi. L'uso |
Esempio
In questo esempio viene illustrato come applicare l'oggetto ClassInterfaceAttribute a un tipo, impostando .ClassInterfaceType Le classi definite in questo modo possono essere usate da COM non gestito.
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
Commenti
Questa enumerazione viene utilizzata insieme all'attributo ClassInterfaceAttribute .