ComVisibleAttribute-Klasse

 

Veröffentlicht: Oktober 2016

Steuert den Zugriff eines einzelnen verwalteten Typs oder Members oder aller Typen innerhalb einer Assembly für COM.

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

Vererbungshierarchie

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

Syntax

[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

Konstruktoren

Name Beschreibung
System_CAPS_pubmethod ComVisibleAttribute(Boolean)

Initialisiert eine neue Instanz der ComVisibleAttribute-Klasse.

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 einen Wert, der angibt, ob der Typ für COM sichtbar ist.

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, 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.

Beispiele

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;
      }

   }

};

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

System.Runtime.InteropServices-Namespace
Tlbexp.exe (Type Library Exporter)
Assembly to Type Library Conversion Summary

Zurück zum Anfang