Compartir a través de


Clase ComVisibleAttribute

 

Publicado: octubre de 2016

Controla la accesibilidad a COM de un tipo o miembro administrado individual, o de todos los tipos que están dentro de un ensamblado.

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

Jerarquía de herencia

System.Object
  System.Attribute
    System.Runtime.InteropServices.ComVisibleAttribute

Sintaxis

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

Constructores

Nombre Descripción
System_CAPS_pubmethod ComVisibleAttribute(Boolean)

Inicializa una nueva instancia de la clase ComVisibleAttribute.

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 un valor que indica si el tipo COM es visible.

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, interfaces, classes, structures, delegates, enumerations, fields, methods, or properties.

The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. Only public types can be made visible. The attribute cannot be used to make an otherwise internal or protected type visible to COM or to make members of a nonvisible type visible.

Setting the attribute to false on the assembly hides all public types within the assembly. You can selectively make types within the assembly visible by setting the individual types to true. Setting the attribute to false on a specific type hides that type and its members. However, you cannot make members of a type visible if the type is invisible. Setting the attribute to false on a type prevents that type from being exported to a type library; classes are not registered; interfaces are never responsive to unmanaged QueryInterface calls.

Unless you explicitly set a class and its members to false, inherited classes can expose to COM base class members that are invisible in the original class. For example, if you set ClassA to false and do not apply the attribute to its members, the class and its members are invisible to COM. However, if you derive ClassB from ClassA and export ClassB to COM, ClassA members become visible base class members of ClassB.

For a detailed description of the export process, see Assembly to Type Library Conversion Summary.

Ejemplos

The following example shows how you can control the visibility to COM of a class so that its members are invisible. By setting ComVisibleAttribute to false on MyClass(SampleClass in the Visual Basic example), and false on MyMethod and MyProperty, you can avoid inadvertently exposing the members to COM through inheritance.

using System.Runtime.InteropServices;

[ComVisible(false)]
class MyClass
{
   public MyClass()
   {
      //Insert code here.
   }

   [ComVisible(false)]
   public int MyMethod(string param) 
   {
      return 0;
   }

   public bool MyOtherMethod() 
   {
      return true;
   }

   [ComVisible(false)]
   public int MyProperty
   {
      get
      {
         return MyProperty;
      }
   }
}
Imports System.Runtime.InteropServices

<ComVisible(False)> _
Class SampleClass

    Public Sub New()
        'Insert code here.
    End Sub

    <ComVisible(False)> _
    Public Function MyMethod(param As String) As Integer
        Return 0
    End Function    

    Public Function MyOtherMethod() As Boolean
        Return True
    End Function

    <ComVisible(False)> _
    Public ReadOnly Property MyProperty() As Integer
        Get
            Return MyProperty
        End Get
    End Property

End Class
using namespace System::Runtime::InteropServices;

[ComVisible(false)]
ref class MyClass
{
private:
   int myProperty;

public:
   MyClass()
   {

      //Insert code here.
   }


   [ComVisible(false)]
   int MyMethod( String^ param )
   {
      return 0;
   }

   bool MyOtherMethod()
   {
      return true;
   }


   property int MyProperty 
   {

      [ComVisible(false)]
      int get()
      {
         return myProperty;
      }

   }

};

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

Espacio de nombres System.Runtime.InteropServices
Tlbexp.exe (Type Library Exporter)
Assembly to Type Library Conversion Summary

Volver al principio