Compartir a través de


Clase ClassInterfaceAttribute

 

Indica el tipo de interfaz de clase que se generará para una clase expuesta a COM si no se genera una interfaz.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

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

Sintaxis

[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

Constructores

Nombre Descripción
System_CAPS_pubmethod ClassInterfaceAttribute(ClassInterfaceType)

Inicializa una nueva instancia de la ClassInterfaceAttribute clase con los valores especificados ClassInterfaceType miembro de enumeración.

System_CAPS_pubmethod ClassInterfaceAttribute(Int16)

Inicializa una nueva instancia de la ClassInterfaceAttribute clase con especificado ClassInterfaceType valor de enumeración.

Propiedades

Nombre Descripción
System_CAPS_pubproperty TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.(Heredado de Attribute).

System_CAPS_pubproperty Value

Obtiene el ClassInterfaceType valor que describe qué tipo de interfaz debe generarse para la clase.

Métodos

Nombre Descripción
System_CAPS_pubmethod Equals(Object)

Esta API admite la infraestructura producto y no está diseñada para usarse directamente desde el código. Devuelve un valor que indica si esta instancia es igual que un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod GetHashCode()

Devuelve el código hash de esta instancia.(Heredado de Attribute).

System_CAPS_pubmethod GetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_pubmethod IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.(Heredado de Attribute).

System_CAPS_pubmethod Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod ToString()

Devuelve una cadena que representa el objeto actual.(Heredado de Object).

Implementaciones de interfaz explícitas

Nombre Descripción
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).(Heredado de Attribute).

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

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.(Heredado de Attribute).

Comentarios

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.

Ejemplos

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(){}

};

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1

Seguridad para subprocesos

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Ver también

ClassInterfaceType
Espacio de nombres System.Runtime.InteropServices
Tlbexp.exe (Type Library Exporter)
Tlbimp.exe (Type Library Importer)

Volver al principio