ComVisibleAttribute クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
- 継承
- 属性
例
次の例は、クラスの COM に対する可視性を制御して、そのメンバーが非表示になるようにする方法を示しています。
ComVisibleAttribute を MyClass (Visual Basic 例では SampleClass) で false に設定し、MyMethod と MyProperty で false を設定すると、継承によってメンバーが COM に誤って公開されるのを回避できます。
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
注釈
この属性は、アセンブリ、インターフェイス、クラス、構造体、デリゲート、列挙型、フィールド、メソッド、イベント アクセサー、またはプロパティに適用できます。
既定値は true です。これは、マネージド型が COM に表示されることを示します。 この属性は、パブリック マネージド アセンブリと型を表示するために必要ありません。既定では COM に表示されます。
public型のみを表示できます。 属性を使用して、COM に対してそれ以外の internal または protected 型を表示したり、非表示の型のメンバーを表示したりすることはできません。
属性をアセンブリの false に設定すると、アセンブリ内のすべての public 型が非表示になります。 個々の型を trueに設定することで、アセンブリ内の型を選択的に表示できます。 属性を特定の型で false に設定すると、その型とそのメンバーは非表示になります。 ただし、型が非表示の場合、型のメンバーを表示することはできません。 属性を型に false に設定すると、その型がタイプ ライブラリにエクスポートされなくなります。クラスは登録されません。インターフェイスはアンマネージ QueryInterface 呼び出しに応答しません。
クラスとそのメンバーを明示的に falseに設定しない限り、継承されたクラスは、元のクラスでは見えない COM 基底クラスメンバーに公開できます。 たとえば、ClassA を false に設定し、そのメンバーに属性を適用しない場合、クラスとそのメンバーは COM からは見えません。 ただし、ClassA から ClassB を派生させ、ClassB を COM にエクスポートすると、ClassA メンバーは ClassB の参照可能な基底クラス メンバーになります。
コンストラクター
| 名前 | 説明 |
|---|---|
| ComVisibleAttribute(Boolean) |
|
プロパティ
| 名前 | 説明 |
|---|---|
| TypeId |
派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。 (継承元 Attribute) |
| Value |
COM 型が表示されるかどうかを示す値を取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。 (継承元 Attribute) |
| GetHashCode() |
このインスタンスのハッシュ コードを返します。 (継承元 Attribute) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| IsDefaultAttribute() |
派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。 (継承元 Attribute) |
| Match(Object) |
派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。 (継承元 Attribute) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
一連の名前を対応する一連のディスパッチ識別子に割り当てます。 (継承元 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。 (継承元 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 (継承元 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。 (継承元 Attribute) |