ClassInterfaceAttribute-Klasse

 

Gibt die Art der Klassenschnittstelle an, die für eine für COM verfügbar gemachte Klasse generiert werden soll (sofern überhaupt eine Schnittstelle generiert wird).

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

Vererbungshierarchie

System.Object
  System.Attribute
    System.Runtime.InteropServices.ClassInterfaceAttribute

Syntax

[AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class, 
    Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ClassInterfaceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly | AttributeTargets::Class, 
    Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ClassInterfaceAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class,
    Inherited = false)>]
[<ComVisibleAttribute(true)>]
type ClassInterfaceAttribute = 
    class
        inherit Attribute
    end
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class,
    Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class ClassInterfaceAttribute
    Inherits Attribute

Konstruktoren

Name Beschreibung
System_CAPS_pubmethod ClassInterfaceAttribute(ClassInterfaceType)

Initialisiert eine neue Instanz der dem ClassInterfaceAttribute Klasse mit dem angegebenen ClassInterfaceType Enumerationsmember.

System_CAPS_pubmethod ClassInterfaceAttribute(Int16)

Initialisiert eine neue Instanz von der ClassInterfaceAttribute -Klasse mit dem angegebenen ClassInterfaceType -Enumerationswert.

Eigenschaften

Name Beschreibung
System_CAPS_pubproperty TypeId

Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.(Geerbt von „Attribute“.)

System_CAPS_pubproperty Value

Ruft den ClassInterfaceType -Wert, der beschreibt, welche Art von Schnittstelle für die Klasse generiert werden soll.

Methoden

Name Beschreibung
System_CAPS_pubmethod Equals(Object)

Diese API unterstützt die Produkt Infrastruktur und sollte nicht direkt aus dem Code verwendet werden. Gibt einen Wert zurück, der angibt, ob diese Instanz gleich einem angegebenen Objekt ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod GetHashCode()

Gibt den Hashcode für diese Instanz zurück.(Geerbt von „Attribute“.)

System_CAPS_pubmethod GetType()

Ruft den Type der aktuellen Instanz ab.(Geerbt von „Object“.)

System_CAPS_pubmethod IsDefaultAttribute()

Gibt beim Überschreiben in einer abgeleiteten Klasse an, ob der Wert der Instanz der Standardwert für die abgeleitete Klasse ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod Match(Object)

Ruft beim Überschreiben in einer abgeleiteten Klasse gibt einen Wert, der angibt, ob diese Instanz gleich ein angegebenen Objekt ist.(Geerbt von „Attribute“.)

System_CAPS_pubmethod ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.(Geerbt von „Object“.)

Explizite Schnittstellenimplementierungen

Name Beschreibung
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Ordnet eine Reihe von Namen einer entsprechenden Reihe von Dispatchbezeichnern zu.(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Ruft die Typinformationen für ein Objekt ab, mit deren Hilfe die Typinformationen für eine Schnittstelle abgerufen werden können.(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Ruft die Anzahl der Schnittstellen mit Typinformationen ab, die von einem Objekt bereitgestellt werden (0 oder 1).(Geerbt von „Attribute“.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Stellt den Zugriff auf von einem Objekt verfügbar gemachte Eigenschaften und Methoden bereit.(Geerbt von „Attribute“.)

Hinweise

You can apply this attribute to assemblies or classes.

This attribute controls whether the Type Library Exporter (Tlbexp.exe) automatically generates a class interface for the attributed class. A class interface carries the same name as the class itself, but the name is prefixed with an underscore. When exposed, the class interface contains all the public, non- static members of the managed class, including members inherited from its base class. Managed classes cannot access a class interface and have no need to as they can access the class members directly. Tlbexp.exe generates a unique interface identifier (IID) for the class interface.

Class interfaces can be dual or dispatch-only interfaces. Optionally, you can suppress the generation of the class interface and provide a custom interface instead. You expose or suppress a class interface by specifying a T:System.Runtime.InteropServices.ClassInterfaceType enumeration member. When you apply T:System.Runtime.InteropServices.ClassInterfaceAttribute to an assembly, the attribute pertains to all classes in the assembly unless the individual classes override the setting with their own attribute.

Although class interfaces eliminate the task of explicitly defining interfaces for each class, their use in production applications is strongly discouraged. Dual class interfaces allow clients to bind to a specific interface layout that is subject to change as the class evolves. For example, consider a managed class that exposes a class interface to COM clients. The first version of the class contains methods North and South. An unmanaged client can bind to the class interface, which provides North as the first method in the class interface and method South as the second method. Now consider the next version of the class, which has a new method, East, inserted between methods North and South. Unmanaged clients that try to bind to the new class through the old class interface end up calling method East when they intend to call method South, because the positioning of methods within the interface has changed. Moreover, any change to the layout of a base class also affects the layout of the class interface for all derived classes. Managed clients, which bind directly to classes, do not exhibit the same versioning problems. For specific guidelines on using a class interface, see COM Callable Wrapper.

The [<topic://cpgrftypelibraryImportertlbimpexe>] always applies to imported classes the F:System.Runtime.InteropServices.ClassInterfaceType.None enumeration member to indicate that existing COM classes never expose managed interfaces.

Beispiele

The following example shows how to apply the T:System.Runtime.InteropServices.ClassInterfaceAttribute with the T:System.Runtime.InteropServices.ClassInterfaceType value F:System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch, which generates an IDispatch interface for MyClass.

using System.Runtime.InteropServices;

[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass
{
   public MyClass() {}
}
Imports System.Runtime.InteropServices

<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class SampleClass    
    ' Insert class members here.
End Class
using namespace System::Runtime::InteropServices;

[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class MyClass
{
public:
   MyClass(){}

};

Versionsinformationen

Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Windows Phone
Verfügbar seit 8.1

Threadsicherheit

Alle öffentlichen statischen Member ( Shared in Visual Basic) dieses Typs sind threadsicher. Die Threadsicherheit für Instanzmember ist nicht garantiert.

Siehe auch

ClassInterfaceType
System.Runtime.InteropServices-Namespace
Tlbexp.exe (Type Library Exporter)
Tlbimp.exe (Type Library Importer)

Zurück zum Anfang