ClassInterfaceType Перечисление
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Определяет тип интерфейса класса, созданного для класса.
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
- Наследование
- Атрибуты
Поля
| Имя | Значение | Описание |
|---|---|---|
| None | 0 | Указывает, что для класса не создается интерфейс класса. Если интерфейсы не реализованы явным образом, класс может предоставлять доступ только через интерфейс с поздней привязкой
Tlbexp.exe (экспортер библиотек типов) предоставляет первый общедоступный, видимый COM-интерфейс, реализованный классом в качестве интерфейса по умолчанию для сокласса. В .NET Framework 2.0 и более поздних версиях можно указать интерфейс по умолчанию, предоставляемый COM, с помощью атрибута ComDefaultInterfaceAttribute. Если класс не реализует интерфейсы, первый общедоступный, видимый COM-интерфейс, реализованный базовым классом, становится интерфейсом по умолчанию (начиная с последнего производного базового класса и работы назад). Tlbexp.exe предоставляется |
| AutoDispatch | 1 | Указывает, что класс поддерживает только позднюю привязку для com-клиентов. Класс Это параметр по умолчанию для ClassInterfaceAttribute. |
| AutoDual | 2 | Указывает, что интерфейс двойного класса автоматически создается для класса и предоставляется com. Сведения о типе создаются для интерфейса класса и публикуются в библиотеке типов. Использование |
Примеры
В этом примере показано, как применить тип ClassInterfaceAttribute , задав параметр ClassInterfaceType. Классы, определенные таким образом, можно использовать из неуправляемого 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
Комментарии
Это перечисление используется в сочетании с атрибутом ClassInterfaceAttribute .