ComVisibleAttribute Sınıf
Tanım
Tek bir yönetilen türün veya üyenin veya bir derleme içindeki tüm türlerin COM 'a erişilebilirliğini denetler.Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.
public ref class ComVisibleAttribute sealed : Attribute
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)]
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
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)>]
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
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek, üyelerinin görünmez olması için bir sınıfın COM ' un görünürlüğünü nasıl denetleyekullanabileceğinizi gösterir.The following example shows how you can control the visibility to COM of a class so that its members are invisible. ' ComVisibleAttribute
false
MyClass
SampleClass
İ (Visual Basic örneğinde) olarak ayarlayarak ve ve ' de false
MyMethod
, ve ' de MyProperty
ÜYELERIN devralmayla, devralınan üyeleri yanlışlıkla com 'a açığa çıkarmaktan kaçınabilirsiniz.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
Açıklamalar
Bu özniteliği derlemeler, arabirimler, sınıflar, yapılar, temsilciler, numaralandırmalar, alanlar, Yöntemler veya özelliklere uygulayabilirsiniz.You can apply this attribute to assemblies, interfaces, classes, structures, delegates, enumerations, fields, methods, or properties.
Varsayılan değer true
, yönetilen TÜRÜN com 'a görünür olduğunu gösterir.The default is true
, which indicates that the managed type is visible to COM. Ortak yönetilen derlemeleri ve türleri görünür yapmak için bu öznitelik gerekli değildir; Varsayılan olarak COM tarafından görülebilir.This attribute is not needed to make public managed assemblies and types visible; they are visible to COM by default. Yalnızca public
türler görünebilir yapılabilir.Only public
types can be made visible. Özniteliği, başka bir şekilde internal
veya bir protected
türü com olarak görünür yapmak ya da görünür olmayan bir türün üyelerini görünür yapmak için kullanılamaz.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.
Özniteliği derlemede olarak ayarlamak false
public
, derleme içindeki tüm türleri gizler.Setting the attribute to false
on the assembly hides all public
types within the assembly. Tek tek türleri olarak ayarlayarak derleme içindeki türleri seçerek görünür hale getirebilirsiniz true
.You can selectively make types within the assembly visible by setting the individual types to true
. Özniteliği false
belirli bir tür üzerinde olarak ayarlamak, bu türü ve üyelerini gizler.Setting the attribute to false
on a specific type hides that type and its members. Ancak, tür görünmez olduğunda bir türün üyelerini görünür hale getirebilirsiniz.However, you cannot make members of a type visible if the type is invisible. Özniteliği false
bir tür üzerinde olarak ayarlamak, bu türün bir tür kitaplığına aktarılmasını önler; sınıflar kaydedilmezler; arabirimler hiçbir şekilde yönetilmeyen çağrılara yanıt vermez QueryInterface
.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.
Açıkça bir sınıfı ve üyelerini olarak ayarlamadığınız takdirde false
, devralınan sınıflar orijinal sınıfta görünmeyen com temel sınıf üyelerine sunabilir.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. Örneğin, ClassA 'yı olarak ayarlarsanız false
ve üyelerini üyelerine uygulamazsanız, sınıfı ve ÜYELERI com 'a görünmez.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. Ancak, ClassA 'dan ClassB 'yi türetirsiniz ve ClassB 'yi COM 'a verirseniz, ClassA üyeleri ClassB 'nin görünür temel sınıf üyeleri haline gelir.However, if you derive ClassB from ClassA and export ClassB to COM, ClassA members become visible base class members of ClassB.
Dışarı aktarma işleminin ayrıntılı bir açıklaması için bkz. derlemeden tür kitaplığı dönüştürme Özeti.For a detailed description of the export process, see Assembly to Type Library Conversion Summary.
Oluşturucular
ComVisibleAttribute(Boolean) |
|
Özellikler
TypeId |
Türetilmiş bir sınıfta uygulandığında, bunun için benzersiz bir tanımlayıcı alır Attribute .When implemented in a derived class, gets a unique identifier for this Attribute. (Devralındığı yer: Attribute) |
Value |
COM türünün görünür olup olmadığını gösteren bir değer alır.Gets a value that indicates whether the COM type is visible. |
Yöntemler
Equals(Object) |
Bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değeri döndürür.Returns a value that indicates whether this instance is equal to a specified object. (Devralındığı yer: Attribute) |
GetHashCode() |
Bu örneğe ilişkin karma kodu döndürür.Returns the hash code for this instance. (Devralındığı yer: Attribute) |
GetType() |
TypeGeçerli örneği alır.Gets the Type of the current instance. (Devralındığı yer: Object) |
IsDefaultAttribute() |
Türetilmiş bir sınıfta geçersiz kılınırsa, bu örneğin değerinin türetilmiş sınıf için varsayılan değer olup olmadığını gösterir.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Devralındığı yer: Attribute) |
Match(Object) |
Türetilmiş bir sınıfta geçersiz kılınırsa, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Devralındığı yer: Attribute) |
MemberwiseClone() |
Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object. (Devralındığı yer: Object) |
ToString() |
Geçerli nesneyi temsil eden dizeyi döndürür.Returns a string that represents the current object. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler.Maps a set of names to a corresponding set of dispatch identifiers. (Devralındığı yer: Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Bir arabirimin tür bilgilerini almak için kullanılabilen bir nesnenin tür bilgilerini alır.Retrieves the type information for an object, which can be used to get the type information for an interface. (Devralındığı yer: Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Devralındığı yer: Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Bir nesne tarafından sunulan özelliklere ve yöntemlere erişim sağlar.Provides access to properties and methods exposed by an object. (Devralındığı yer: Attribute) |