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

ConfigurationPropertyAttribute クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

.NET Framework構成プロパティインスタンス化するように、宣言によって指示します。このクラス継承できません。

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

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

ConfigurationPropertyAttribute使用して.NET Frameworkインスタンス化指示する構成プロパティ装飾し装飾パラメータの値を使用してプロパティ初期化します。

メモメモ

カスタム構成要素作成する最も簡単な方法は、属性付き (宣言) モデル使用することです。カスタムパブリック プロパティ宣言し、それらを ConfigurationPropertyAttribute 属性装飾します。.NET Framework は、この属性マークされプロパティごとに、リフレクション使用して装飾パラメータ読み取り関連する ConfigurationProperty インスタンス作成しますまた、プログラム モデル使用できます。この場合には、開発者が、カスタムパブリック プロパティ宣言し、それらのコレクション返す必要があります

.NET Framework 構成システムには、カスタム構成要素作成時に使用できる属性の型が用意されています。2 種類属性の型があります

  1. .NET Framework に、カスタム構成要素プロパティインスタンス化する方法指示する型。次の属性がこれらの型に含まれます。

    • ConfigurationCollectionAttribute

    • ConfigurationPropertyAttribute

  2. .NET Framework に、カスタム構成要素プロパティ検証する方法指示する型。次の属性がこれらの型に含まれます。

    • IntegerValidatorAttribute

    • LongValidatorAttribute

    • RegexStringValidatorAttribute

    • StringValidatorAttribute

    • TimeSpanValidatorAttribute

使用例使用例

ConfigurationPropertyAttribute 属性使用してカスタム ConfigurationSection オブジェクトプロパティ装飾する方法を、次のコード例示します

Public Class SampleSection
   Inherits ConfigurationSection
   
   Public Sub New()
   End Sub 'New
   
   
    <ConfigurationProperty("fileName", _
    DefaultValue:="default.txt", _
    IsRequired:=True, _
    IsKey:=False), _
    StringValidator( _
    InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\",
 _
    MinLength:=1, _
    MaxLength:=60)> _
    Public Property FileName() As
 String
        Get
            Return CStr(Me("fileName"))
        End Get
        Set(ByVal value As
 String)
            Me("fileName") = value
        End Set
    End Property


    <ConfigurationProperty("maxUsers", _
    DefaultValue:=10000, _
    IsRequired:=False), _
    LongValidator(MinValue:=1, _
    MaxValue:=10000000, _
    ExcludeRange:=False)> _
   Public Property MaxUsers() As
 Long
        Get
            Return Fix(Me("maxUsers"))
        End Get
        Set(ByVal value As
 Long)
            Me("maxUsers") = value
        End Set
    End Property

    <ConfigurationProperty("maxIdleTime", _
    DefaultValue:="0:10:0", _
    IsRequired:=False), _
    TimeSpanValidator(MinValueString:="0:0:30", _
    MaxValueString:="5:00:0", _
    ExcludeRange:=False)> _
    Public Property MaxIdleTime() As
 TimeSpan
        Get
            Return CType(Me("maxIdleTime"),
 TimeSpan)
        End Get
        Set(ByVal value As
 TimeSpan)
            Me("maxIdleTime") =
 value
        End Set
    End Property
   
public class SampleSection : 
    ConfigurationSection
{
    public SampleSection()
    {
    }

    [ConfigurationProperty("fileName", DefaultValue = "default.txt"
,
        IsRequired = true, IsKey = false)]
    [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\"
,
        MinLength = 1, MaxLength = 60)]
    public string FileName
    {
        get
        {
            return (string)this["fileName"];
        }
        set
        {
            this["fileName"] = value;
        }
    }

    [ConfigurationProperty("maxUsers", DefaultValue = (long)10000,  
        IsRequired=false)]
    [LongValidator(MinValue = 1, MaxValue = 10000000,
        ExcludeRange = false)]
    public long MaxUsers
    {
        get
        {
            return (long)this["maxUsers"];
        }
        set
        {
            this["maxUsers"] = value;
        }
    }

    [ConfigurationProperty("maxIdleTime",
        DefaultValue = "0:10:0",
        IsRequired = false)]
    [TimeSpanValidator(MinValueString = "0:0:30", 
        MaxValueString = "5:00:0",
        ExcludeRange = false)]
    public TimeSpan MaxIdleTime
    {
        get
        {
            return (TimeSpan)this["maxIdleTime"];
        }
        set
        {
            this["maxIdleTime"] = value;
        }
    }
}

以下は、前の例で定義されていたカスタム セクション含まれる構成ファイルからの抜粋です。

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
    <section name="custom" type="Samples.AspNet.SampleSection, ConfigurationPropertyAttribute"
 />
  </configSections>
  <custom fileName="Default.txt" 
    maxUsers="2500" maxIdleTime="00:10:00" />
</configuration>
継承階層継承階層
System.Object
   System.Attribute
    System.Configuration.ConfigurationPropertyAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConfigurationPropertyAttribute メンバ
System.Configuration 名前空間
ConfigurationProperty クラス
ConfigurationCollectionAttribute クラス
IntegerValidatorAttribute
LongValidatorAttribute
RegexStringValidatorAttribute
StringValidatorAttribute
TimeSpanValidatorAttribute

ConfigurationPropertyAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

ConfigurationPropertyAttribute クラス新しインスタンス初期化します。

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

Dim name As String

Dim instance As New ConfigurationPropertyAttribute(name)
public ConfigurationPropertyAttribute (
    string name
)
public:
ConfigurationPropertyAttribute (
    String^ name
)
public ConfigurationPropertyAttribute (
    String name
)
public function ConfigurationPropertyAttribute
 (
    name : String
)

パラメータ

name

定義された ConfigurationProperty オブジェクトの名前。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConfigurationPropertyAttribute クラス
ConfigurationPropertyAttribute メンバ
System.Configuration 名前空間

ConfigurationPropertyAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ DefaultValue 装飾されプロパティ既定値取得または設定します
パブリック プロパティ IsDefaultCollection これが、装飾され構成プロパティ対す既定プロパティコレクションかどうかを示す値を取得または設定します
パブリック プロパティ IsKey これが、装飾され要素プロパティ対する主要プロパティかどうかを示す値を取得または設定します
パブリック プロパティ IsRequired 装飾され要素プロパティが必要かどうかを示す値を取得または設定します
パブリック プロパティ Name 装飾され構成要素プロパティの名前を取得または設定します
パブリック プロパティ Options 装飾され構成要素プロパティの ConfigurationPropertyOptions を取得または設定します
パブリック プロパティ TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
参照参照

関連項目

ConfigurationPropertyAttribute クラス
System.Configuration 名前空間
ConfigurationProperty クラス
ConfigurationCollectionAttribute クラス
IntegerValidatorAttribute
LongValidatorAttribute
RegexStringValidatorAttribute
StringValidatorAttribute
TimeSpanValidatorAttribute

ConfigurationPropertyAttribute メソッド


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

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

関連項目

ConfigurationPropertyAttribute クラス
System.Configuration 名前空間
ConfigurationProperty クラス
ConfigurationCollectionAttribute クラス
IntegerValidatorAttribute
LongValidatorAttribute
RegexStringValidatorAttribute
StringValidatorAttribute
TimeSpanValidatorAttribute

ConfigurationPropertyAttribute メンバ

.NET Framework構成プロパティインスタンス化するように、宣言によって指示します。このクラス継承できません。

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


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

関連項目

ConfigurationPropertyAttribute クラス
System.Configuration 名前空間
ConfigurationProperty クラス
ConfigurationCollectionAttribute クラス
IntegerValidatorAttribute
LongValidatorAttribute
RegexStringValidatorAttribute
StringValidatorAttribute
TimeSpanValidatorAttribute



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

辞書ショートカット

すべての辞書の索引

「ConfigurationPropertyAttribute」の関連用語

ConfigurationPropertyAttributeのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS