DesignOnlyAttribute クラス

定義

プロパティをデザイン時にのみ設定できるかどうかを指定します。

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

次の例では、 GetLanguage プロパティを作成します。 プロパティは DesignOnlyAttributeでマークされます。

public:
   [DesignOnly(true)]
   property CultureInfo^ GetLanguage 
   {
      CultureInfo^ get()
      {
         // Insert code here.
         return myCultureInfo;
      }
      void set( CultureInfo^ value )
      {
         // Insert code here.
      }
   }
[DesignOnly(true)]
public CultureInfo GetLanguage
{
    get =>
        // Insert code here.
        myCultureInfo;
    set
    {
        // Insert code here.
    }
}
<DesignOnly(True)> _
Public Property GetLanguage() As CultureInfo
    Get
        ' Insert code here.
        Return myCultureInfo
    End Get
    Set
        ' Insert code here.
    End Set
End Property

次の例では、 DesignOnlyAttributeの値を取得します。 まず、コードはオブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。 次に、 PropertyDescriptorCollection にインデックスを作成して、 GetLanguage プロパティを検索します。 次に、このプロパティの属性を返し、属性変数に保存します。

次に、プロパティがデザインであるかどうかを出力するには、AttributeCollectionからDesignOnlyAttributeを取得し、コンソール画面に書き込みます。

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

/* Prints whether the property is marked as DesignOnly 
by retrieving the DesignOnlyAttribute from the AttributeCollection. */
DesignOnlyAttribute^ myAttribute = dynamic_cast<DesignOnlyAttribute^>(attributes[ DesignOnlyAttribute::typeid ]);
Console::WriteLine( "This property is design only :{0}", myAttribute->IsDesignOnly );
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes;

/* Prints whether the property is marked as DesignOnly 
 * by retrieving the DesignOnlyAttribute from the AttributeCollection. */
DesignOnlyAttribute myAttribute =
   (DesignOnlyAttribute)attributes[typeof(DesignOnlyAttribute)];
Console.WriteLine("This property is design only :" +
   myAttribute.IsDesignOnly.ToString());
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes

' Prints whether the property is marked as DesignOnly 
' by retrieving the DesignOnlyAttribute from the AttributeCollection.
Dim myAttribute As DesignOnlyAttribute = _
    CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute)
Console.WriteLine(("This property is design only :" & _
    myAttribute.IsDesignOnly.ToString()))

注釈

DesignOnlyAttributetrueに設定されたメンバーは、デザイン時にのみ設定できます。 通常、これらのプロパティはデザイン時にのみ存在し、実行時にオブジェクトの実際のプロパティには対応しません。

属性を持たないメンバー、または DesignOnlyAttributefalse に設定されているメンバーは、実行時に設定できます。 既定値は false です。

DesignOnlyAttributetrue に設定されているプロパティの値は、InitializeComponent メソッドではなく .resx ファイルにシリアル化されます。

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

コンストラクター

名前 説明
DesignOnlyAttribute(Boolean)

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

フィールド

名前 説明
Default

DesignOnlyAttributeの既定値 (No) を指定します。 この static フィールドは読み取り専用です。

No

プロパティをデザイン時または実行時に設定できることを指定します。 この static フィールドは読み取り専用です。

Yes

プロパティをデザイン時にのみ設定できることを指定します。 この static フィールドは読み取り専用です。

プロパティ

名前 説明
IsDesignOnly

デザイン時にのみプロパティを設定できるかどうかを示す値を取得します。

TypeId

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

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

指定したオブジェクトの値が現在の DesignOnlyAttributeと等しいかどうかを返します。

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)

適用対象

こちらもご覧ください