Language

MergablePropertyAttribute クラス

定義

このプロパティを、プロパティ ウィンドウ内の他のオブジェクトに属するプロパティと組み合わせることができることを指定します。

public ref class MergablePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MergablePropertyAttribute : Attribute
public sealed class MergablePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type MergablePropertyAttribute = class
    inherit Attribute
type MergablePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class MergablePropertyAttribute
Inherits Attribute
継承
MergablePropertyAttribute
属性

例

次の例では、マージに必要なプロパティをマークします。

public:
   [MergableProperty(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[MergableProperty(true)]
public int MyProperty
{
    get =>
        // Insert code here.
        0;
    set
    {
        // Insert code here.
    }
}
<MergableProperty(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

次の例では、MergablePropertyAttributeのMyPropertyの値を確認する方法を示します。 まず、コードはオブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。 次に、PropertyDescriptorCollectionを取得するためにMyPropertyにインデックスを作成します。 次に、このプロパティの属性を返し、属性変数に保存します。

この例では、 MergablePropertyAttributeの値を確認する 2 つの異なる方法を示します。 2 番目のコード フラグメントでは、Equals値を使用して static メソッドを呼び出します。 最後のコード フラグメントでは、 AllowMerge プロパティを使用して値を確認します。

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}

// This is another way to see if the property is bindable.
MergablePropertyAttribute^ myAttribute = dynamic_cast<MergablePropertyAttribute^>(attributes[ MergablePropertyAttribute::typeid ]);
if ( myAttribute->AllowMerge )
{
   // Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see if the value of the MergablePropertyAttribute is Yes.
if (attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes))
{
    // Insert code here.
}

// This is another way to see if the property is bindable.
MergablePropertyAttribute myAttribute =
   (MergablePropertyAttribute)attributes[typeof(MergablePropertyAttribute)];
if (myAttribute.AllowMerge)
{
    // Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the value of the MergablePropertyAttribute is Yes.
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If 

' This is another way to see if the property is bindable.
Dim myAttribute As MergablePropertyAttribute = _
    CType(attributes(GetType(MergablePropertyAttribute)), MergablePropertyAttribute)
If myAttribute.AllowMerge Then
    ' Insert code here.
End If

MergablePropertyAttributeでクラスをマークした場合は、次のコードを使用して値を確認します。

AttributeCollection^ attributes = TypeDescriptor::GetAttributes( MyProperty );
if ( attributes[ MergablePropertyAttribute::typeid ]->Equals( MergablePropertyAttribute::Yes ) )
{
   // Insert code here.
}
AttributeCollection attributes =
    TypeDescriptor.GetAttributes(MyProperty);
if (attributes[typeof(MergablePropertyAttribute)].Equals(MergablePropertyAttribute.Yes))
{
    // Insert code here.
}
Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(MyProperty)
If attributes(GetType(MergablePropertyAttribute)).Equals(MergablePropertyAttribute.Yes) Then
    ' Insert code here.
End If

注釈

MergablePropertyAttributeに設定されたtrueでマークされたプロパティは、[プロパティ] ウィンドウ内の他のオブジェクトに属するプロパティと組み合わせることができます。 MergablePropertyAttributeが false に設定されているプロパティは、個別に表示する必要があります。 既定値は true です。

Note

MergablePropertyAttributeを true に設定してプロパティをマークすると、この属性の値は定数メンバー Yesに設定されます。 MergablePropertyAttribute プロパティが false に設定されたプロパティの場合、値はNo。 したがって、コードでこの属性の値を確認する場合は、属性を MergablePropertyAttribute.Yes または MergablePropertyAttribute.Noとして指定する必要があります。

詳細については、「属性」を参照してください。

コンストラクター

名前 説明
MergablePropertyAttribute(Boolean)

MergablePropertyAttribute クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
Default

プロパティ ウィンドウ内の他のオブジェクトに属するプロパティと組み合わせることができる既定値 ( Yes) を指定します。 この static フィールドは読み取り専用です。

No

[プロパティ] ウィンドウ内の他のオブジェクトに属するプロパティとプロパティを組み合わせることができないことを指定します。 この static フィールドは読み取り専用です。

Yes

[プロパティ] ウィンドウ内の他のオブジェクトに属するプロパティとプロパティを組み合わせることができることを指定します。 この static フィールドは読み取り専用です。

プロパティ

名前 説明
AllowMerge

プロパティ ウィンドウ内の他のオブジェクトに属するプロパティとこのプロパティを組み合わせることができるかどうかを示す値を取得します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

このインスタンスと指定したオブジェクトが等しいかどうかを示します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

この属性が既定であるかどうかを判断します。

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)

適用対象

こちらもご覧ください