DesignOnlyAttribute クラスとは? わかりやすく解説

DesignOnlyAttribute クラス

プロパティ設定できるのがデザイン時だけかどうか指定します

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.All)> _
Public NotInheritable Class
 DesignOnlyAttribute
    Inherits Attribute
Dim instance As DesignOnlyAttribute
[AttributeUsageAttribute(AttributeTargets.All)] 
public sealed class DesignOnlyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] 
public ref class DesignOnlyAttribute sealed
 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ 
public final class DesignOnlyAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.All) 
public final class DesignOnlyAttribute extends
 Attribute
解説解説
使用例使用例

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

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

/** @property 
 */
public void set_GetLanguage(CultureInfo value)
{
    // Insert code here.
} //set_GetLanguage

DesignOnlyAttribute の値を取得する例を次に示します最初にオブジェクトすべてのプロパティ保持する PropertyDescriptorCollection を取得します次にインデックス付けて PropertyDescriptorCollection から GetLanguage プロパティ検索します。そして、このプロパティ属性返し、その属性属性変数保存します

最後に、AttributeCollection から DesignOnlyAttribute取得し取得した情報コンソール画面書き込むことによって、プロパティ設定できるのがデザイン時だけかどうか出力します

' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes

' Prints the description by retrieving the DescriptionAttribute
' from the AttributeCollection. 
Dim myAttribute As DesignOnlyAttribute = _
    CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute)
Console.WriteLine(("This property is design only :"
 & _
    myAttribute.IsDesignOnly.ToString()))
// Gets the attributes for the property.
 AttributeCollection attributes = 
    TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes;
 
 /* Prints the description by retrieving the DescriptionAttribute 
  * 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.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this
 )[ "GetLanguage" ]->Attributes;

/* Prints the description by retrieving the DescriptionAttribute 
       * 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).
    get_Item("GetLanguage").get_Attributes();

/* Prints the description by retrieving the DescriptionAttribute 
   from the AttributeCollection. 
 */
DesignOnlyAttribute myAttribute = (DesignOnlyAttribute)(attributes.
    get_Item(DesignOnlyAttribute.class.ToType()));

Console.WriteLine("This property is design only :" 
    + System.Convert.ToString(myAttribute.get_IsDesignOnly()));
継承階層継承階層
System.Object
   System.Attribute
    System.ComponentModel.DesignOnlyAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DesignOnlyAttribute クラス」の関連用語

DesignOnlyAttribute クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DesignOnlyAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS