ComVisibleAttribute Třída
Definice
Řídí přístupnost jednotlivého spravovaného typu nebo člena nebo všech typů v rámci sestavení na modelu COM.Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
public ref class ComVisibleAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)]
public sealed class ComVisibleAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ComVisibleAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)>]
type ComVisibleAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ComVisibleAttribute = class
inherit Attribute
Public NotInheritable Class ComVisibleAttribute
Inherits Attribute
- Dědičnost
- Atributy
Příklady
Následující příklad ukazuje, jak lze řídit viditelnost třídy modelu COM, aby její členové byly neviditelní.The following example shows how you can control the visibility to COM of a class so that its members are invisible. Nastavením na ComVisibleAttribute
false
on MyClass
( SampleClass
v Visual Basicm příkladu) a false
na MyMethod
a MyProperty
můžete vyhnout nechtěnému vystavení členů modelu COM prostřednictvím dědičnosti.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 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;
}
}
};
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
Poznámky
Tento atribut lze použít pro sestavení, rozhraní, třídy, struktury, delegáty, výčty, pole, metody nebo vlastnosti.You can apply this attribute to assemblies, interfaces, classes, structures, delegates, enumerations, fields, methods, or properties.
Výchozí hodnota je true
, což znamená, že spravovaný typ je viditelný pro model COM.The default is true
, which indicates that the managed type is visible to COM. Tento atribut není potřeba k tomu, aby se daly zobrazit veřejná spravovaná sestavení a typy. ve výchozím nastavení jsou v modelu COM viditelné.This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. public
Zobrazit lze pouze typy.Only public
types can be made visible. Atribut nejde použít k tomu, aby se nemohlo internal
Zobrazit jinak nebo protected
typ viditelný pro model COM, nebo aby se zobrazily viditelné členy neviditelného typu.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.
Nastavení atributu na false
sestavení skryje všechny public
typy v rámci sestavení.Setting the attribute to false
on the assembly hides all public
types within the assembly. Můžete selektivně vytvořit typy v rámci sestavení, a to tak, že nastavíte jednotlivé typy na true
.You can selectively make types within the assembly visible by setting the individual types to true
. Nastavení atributu na false
konkrétní typ skrývá tento typ a jeho členy.Setting the attribute to false
on a specific type hides that type and its members. Nicméně nelze nastavit členy typu, pokud je typ neviditelný.However, you cannot make members of a type visible if the type is invisible. Nastavením atributu na false
typ u typu zabráníte, aby byl tento typ exportován do knihovny typů. třídy nejsou registrovány. rozhraní nikdy nereagují na nespravované QueryInterface
volání.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.
Pokud explicitně nenastavíte třídu a její členy na false
, zděděné třídy mohou vystavit členům základních tříd modelu COM, které jsou v původní třídě neviditelné.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. Například pokud nastavíte třídu na false
a nepoužijete atribut na jeho členy, třída a její členové jsou neviditelné v modelu COM.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. Nicméně pokud odvozujete ClassB z třídy Class a a exportujete ClassB do modelu COM, členové třídy Class stanou viditelné členy základní třídy ClassB.However, if you derive ClassB from ClassA and export ClassB to COM, ClassA members become visible base class members of ClassB.
Podrobný popis procesu exportu naleznete v tématu Souhrn převodu sestavení na knihovnu typů.For a detailed description of the export process, see Assembly to Type Library Conversion Summary.
Konstruktory
ComVisibleAttribute(Boolean) |
Inicializuje novou instanci |
Vlastnosti
TypeId |
Při implementaci v odvozené třídě získá jedinečný identifikátor Attribute .When implemented in a derived class, gets a unique identifier for this Attribute. (Zděděno od Attribute) |
Value |
Získá hodnotu, která označuje, zda je typ COM viditelný.Gets a value that indicates whether the COM type is visible. |
Metody
Equals(Object) |
Vrací hodnotu, která určuje, zda je tato instance rovna zadanému objektu.Returns a value that indicates whether this instance is equal to a specified object. (Zděděno od Attribute) |
GetHashCode() |
Vrátí hodnotu hash pro tuto instanci.Returns the hash code for this instance. (Zděděno od Attribute) |
GetType() |
Získá Type aktuální instanci.Gets the Type of the current instance. (Zděděno od Object) |
IsDefaultAttribute() |
Při přepsání v odvozené třídě označuje, zda je hodnota této instance výchozí hodnotou pro odvozenou třídu.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Zděděno od Attribute) |
Match(Object) |
Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda je tato instance rovna zadanému objektu.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Zděděno od Attribute) |
MemberwiseClone() |
Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object. (Zděděno od Object) |
ToString() |
Vrátí řetězec, který představuje aktuální objekt.Returns a string that represents the current object. (Zděděno od Object) |
Explicitní implementace rozhraní
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.Maps a set of names to a corresponding set of dispatch identifiers. (Zděděno od Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Načte informace o typu pro objekt, který lze použít k získání informací o typu pro rozhraní.Retrieves the type information for an object, which can be used to get the type information for an interface. (Zděděno od Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Zděděno od Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Poskytuje přístup k vlastnostem a metodám vystaveným objektem.Provides access to properties and methods exposed by an object. (Zděděno od Attribute) |