DefaultPropertyAttributeとは? わかりやすく解説

DefaultPropertyAttribute クラス

コンポーネントの既定のプロパティを指定します。

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

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

MyControl という名前のコントロールを定義する例を次に示します。このクラスは、既定のプロパティとして MyProperty を指定する DefaultPropertyAttribute を使用してマークされます。

<DefaultProperty("MyProperty")> _
Public Class MyControl
    Inherits Control

    Public Property MyProperty() As
 Integer
        Get
            ' Insert code here.
            Return 0
        End Get
        Set
            ' Insert code here.
        End Set 
    End Property
    ' Insert any additional code.
End Class 'MyControl
[DefaultProperty("MyProperty")]
 public class MyControl : Control {
 
    public int MyProperty {
       get {
          // Insert code here.
          return 0;
       }
       set {
          // Insert code here.
       }
    }
 
    // Insert any additional code.
 
 }
[DefaultProperty("MyProperty")]
ref class MyControl: public Control
{
public:

   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }

      void set( int value
 )
      {
         // Insert code here.
      }
   }
   // Insert any additional code.
};
/** @attribute DefaultProperty("MyProperty")
 */
public static class MyControl
 extends Control
{
    /** @property 
     */
    public int get_MyProperty()
    {
        // Insert code here.
        return 0;
    } //get_MyProperty

    /** @property 
     */
    public void set_MyProperty(int
 value)
    {
        // Insert code here.
    } //set_MyProperty

    // Insert any additional code.

} //MyControl

MyControl のインスタンスを作成する例を次に示します。そのクラスの属性を取得し、DefaultPropertyAttribute を抽出してから、既定のプロパティの名前を出力します。

Public Shared Function Main()
 As Integer
    ' Creates a new control.
    Dim myNewControl As New
 MyControl()
    
    ' Gets the attributes for the collection.
    Dim attributes As AttributeCollection =
 TypeDescriptor.GetAttributes(myNewControl)
    
    ' Prints the name of the default property by retrieving the
    ' DefaultPropertyAttribute from the AttributeCollection. 
    Dim myAttribute As DefaultPropertyAttribute
 = _
        CType(attributes(GetType(DefaultPropertyAttribute)), DefaultPropertyAttribute)
    Console.WriteLine(("The default property is: "
 + myAttribute.Name))
    Return 0
End Function 'Main

public static int Main()
 {
    // Creates a new control.
    MyControl myNewControl = new MyControl();
 
    // Gets the attributes for the collection.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl);
 
    /* Prints the name of the default property by retrieving the
 
     * DefaultPropertyAttribute from the AttributeCollection. */
    DefaultPropertyAttribute myAttribute = 
       (DefaultPropertyAttribute)attributes[typeof(DefaultPropertyAttribute)];
    Console.WriteLine("The default property is: " +
 myAttribute.Name);
  
    return 0;
 }
int main()
{
   // Creates a new control.
   Form1::MyControl^ myNewControl = gcnew Form1::MyControl;

   // Gets the attributes for the collection.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewControl
 );

   /* Prints the name of the default property by retrieving the
 
       * DefaultPropertyAttribute from the AttributeCollection. */
   DefaultPropertyAttribute^ myAttribute = dynamic_cast<DefaultPropertyAttribute^>(attributes[
 DefaultPropertyAttribute::typeid ]);
   Console::WriteLine( "The default property is: {0}",
 myAttribute->Name );
   return 0;
}
public static void main(String[]
 args)
{
    // Creates a new control.        
    MyControl myNewControl = new MyControl();

    // Gets the attributes for the collection.
    AttributeCollection attributes = 
        TypeDescriptor.GetAttributes(myNewControl);

    /* Prints the name of the default property by retrieving the
 
       DefaultPropertyAttribute from the AttributeCollection. 
     */
    DefaultPropertyAttribute myAttribute = 
        (DefaultPropertyAttribute)(attributes.get_Item(
        DefaultPropertyAttribute.class.ToType()));

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

DefaultPropertyAttribute コンストラクタ


DefaultPropertyAttribute フィールド


パブリック フィールドパブリック フィールド

  名前 説明
パブリック フィールド Default DefaultPropertyAttribute の既定値 (null 参照 (Visual Basic では Nothing)) を指定します。static フィールドは読み取り専用です。
参照参照

関連項目

DefaultPropertyAttribute クラス
System.ComponentModel 名前空間
Attribute

DefaultPropertyAttribute プロパティ


DefaultPropertyAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals オーバーロードされます。 オーバーライドされます。 指定したオブジェクトの値が現在の DefaultPropertyAttribute と等しいかどうかを示す値を返します。
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode オーバーライドされます。 対象のインスタンスのハッシュ コードを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DefaultPropertyAttribute クラス
System.ComponentModel 名前空間
Attribute

DefaultPropertyAttribute メンバ

コンポーネントの既定のプロパティを指定します。

DefaultPropertyAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DefaultPropertyAttribute DefaultPropertyAttribute クラスの新しいインスタンスを初期化します。
パブリック フィールドパブリック フィールド
  名前 説明
パブリック フィールド Default DefaultPropertyAttribute の既定値 (null 参照 (Visual Basic では Nothing)) を指定します。static フィールドは読み取り専用です。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals オーバーロードされます。 オーバーライドされます。 指定したオブジェクトの値が現在の DefaultPropertyAttribute と等しいかどうかを示す値を返します。
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode オーバーライドされます。 対象のインスタンスのハッシュ コードを返します。
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DefaultPropertyAttribute クラス
System.ComponentModel 名前空間
Attribute



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「DefaultPropertyAttribute」の関連用語

DefaultPropertyAttributeのお隣キーワード

   

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



DefaultPropertyAttributeのページの著作権

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

©2026 GRAS Group, Inc.RSS