ConfigurationProperty ConfigurationProperty ConfigurationProperty ConfigurationProperty Class

定義

属性または構成要素の子を表します。Represents an attribute or a child of a configuration element. このクラスは継承できません。This class cannot be inherited.

この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。

public ref class ConfigurationProperty sealed
public sealed class ConfigurationProperty
type ConfigurationProperty = class
Public NotInheritable Class ConfigurationProperty
継承
ConfigurationPropertyConfigurationPropertyConfigurationPropertyConfigurationProperty

  1. 次のコード例を使用する方法を示しています、ConfigurationPropertyカスタム セクションを作成する場合。The following code example shows how to use the ConfigurationProperty when you create a custom section.
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;

namespace ConfigurationPropertyExample
{
    // Define a custom section.
    // Shows how to use the ConfigurationProperty
    // class when defining a custom section.
    public sealed class CustomSection : ConfigurationSection
    {
        // The collection (property bag) that contains 
        // the section properties.
        private static ConfigurationPropertyCollection _Properties;

        // The FileName property.
        private static ConfigurationProperty _FileName;

        // The Alias property.
        private static ConfigurationProperty _Alias;

        // The MaxUsers property.
        private static ConfigurationProperty _MaxUsers;

        // The MaxIdleTime property.
        private static ConfigurationProperty _MaxIdleTime;

        // CustomSection constructor.
        static CustomSection()
        {
            // Initialize the _FileName property
            _FileName =
                new ConfigurationProperty("fileName",
                typeof(string), "default.txt");

            // Initialize the _MaxUsers property
            _MaxUsers =
                new ConfigurationProperty("maxUsers",
                typeof(long), (long)1000,
                ConfigurationPropertyOptions.None);

            // Initialize the _MaxIdleTime property
            TimeSpan minTime = TimeSpan.FromSeconds(30);
            TimeSpan maxTime = TimeSpan.FromMinutes(5);

            ConfigurationValidatorBase _TimeSpanValidator =
                new TimeSpanValidator(minTime, maxTime, false);

            _MaxIdleTime =
                new ConfigurationProperty("maxIdleTime",
                typeof(TimeSpan), TimeSpan.FromMinutes(5),
                TypeDescriptor.GetConverter(typeof(TimeSpan)),
                _TimeSpanValidator,
                ConfigurationPropertyOptions.IsRequired,
                "[Description:This is the max idle time.]");

            // Initialize the _Alias property
            _Alias =
                new ConfigurationProperty("alias",
                typeof(string), "alias.txt");

            // Initialize the Property collection.
            _Properties = new ConfigurationPropertyCollection();
            _Properties.Add(_FileName);
            _Properties.Add(_Alias);
            _Properties.Add(_MaxUsers);
            _Properties.Add(_MaxIdleTime);
        }

        // Return the initialized property bag
        // for the configuration element.
        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return _Properties;
            }
        }

        // Clear the property.
        public void ClearCollection()
        {
            Properties.Clear();
        }

        // Remove an element from the property collection.
        public void RemoveCollectionElement(string elName)
        {
            Properties.Remove(elName);
        }

        // Get the property collection enumerator.
        public IEnumerator GetCollectionEnumerator()
        {
            return (Properties.GetEnumerator());
        }

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

        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
            MinLength = 1, MaxLength = 60)]
        public string Alias
        {
            get
            {
                return (string)this["alias"];
            }
            set
            {
                this["alias"] = value;
            }
        }

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

        public TimeSpan MaxIdleTime
        {
            get
            {
                return (TimeSpan)this["maxIdleTime"];
            }
            set
            {
                this["maxIdleTime"] = value;
            }
        }
    }
}
Imports System
Imports System.Configuration
Imports System.Collections
Imports System.ComponentModel

' Define a custom section.
' Shows how to use the ConfigurationProperty
' class when defining a custom section.
Public NotInheritable Class CustomSection
    Inherits ConfigurationSection

    ' The collection (property bag) that contains 
    ' the section properties.
    Private Shared _Properties As ConfigurationPropertyCollection

    ' The FileName property.
    Private Shared _FileName As ConfigurationProperty

    ' The Alias property.
    Private Shared _Alias As ConfigurationProperty

    ' The MasUsers property.
    Private Shared _MaxUsers As ConfigurationProperty

    ' The MaxIdleTime property.
    Private Shared _MaxIdleTime As ConfigurationProperty

    ' CustomSection constructor.
    Shared Sub New()

        ' Initialize the _FileName property
        _FileName = New ConfigurationProperty( _
            "fileName", GetType(String), "default.txt")

        ' Initialize the _MaxUsers property
        _MaxUsers = New ConfigurationProperty( _
            "maxUsers", GetType(Long), 1000L, _
            ConfigurationPropertyOptions.None)

        ' Initialize the _MaxIdleTime property
        Dim minTime As TimeSpan = TimeSpan.FromSeconds(30)
        Dim maxTime As TimeSpan = TimeSpan.FromMinutes(5)
        Dim _TimeSpanValidator = _
            New TimeSpanValidator(minTime, maxTime, False)

        _MaxIdleTime = New ConfigurationProperty( _
            "maxIdleTime", GetType(TimeSpan), _
            TimeSpan.FromMinutes(5), _
            TypeDescriptor.GetConverter(GetType(TimeSpan)), _
            _TimeSpanValidator, _
            ConfigurationPropertyOptions.IsRequired, _
            "[Description:This is the max idle time.]")

        ' Initialize the _Alias property
        _Alias = New ConfigurationProperty( _
            "alias", GetType(String), "alias.txt")

        ' Property collection initialization.
        ' The collection (property bag) that contains 
        ' the properties is declared as:
        ' ConfigurationPropertyCollection _Properties;
        _Properties = New ConfigurationPropertyCollection()
        _Properties.Add(_FileName)
        _Properties.Add(_Alias)
        _Properties.Add(_MaxUsers)
        _Properties.Add(_MaxIdleTime)

    End Sub

    ' Return the initialized property bag
    ' for the configuration element.
    Protected Overrides ReadOnly Property Properties() _
    As ConfigurationPropertyCollection
        Get
            Return _Properties
        End Get
    End Property

    <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

    <StringValidator(InvalidCharacters:= _
    " ~!@#$%^&*()[]{}/;'""|\", MinLength:=1, _
    MaxLength:=60)> _
    Public Property [Alias]() As String
        Get
            Return CStr(Me("alias"))
        End Get
        Set(ByVal value As String)
            Me("alias") = value
        End Set
    End Property

    <LongValidator(MinValue:=1, _
    MaxValue:=1000000, 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

    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
End Class

前の例のコードで使用される構成ファイルの抜粋を次に示します。The following is an excerpt of the configuration file used by the code in the previous example.

<configuration>
  <configSections>
    <section name="CustomSection" type="ConfigurationPropertyExample.CustomSection, ConfigurationPropertyExample" 
      allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" 
      restartOnExternalChanges="true" />
  </configSections>
  <CustomSection fileName="override.txt" alias="alias.txt" 
    maxUsers="1000" maxIdleTime="00:05:00" />
</configuration>

次の例では、コードで、前のセクションを作成する方法を示します。The following example shows how to create the previous section in code.

// Define a custom section programmatically.
static void CreateSection()
{
    try
    {
        CustomSection customSection;

        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

        // Create the section entry  
        // in the <configSections> and the 
        // related target section in <configuration>.
        // Call it "CustomSection2" since the file in this 
        // example already has "CustomSection".
        if (config.Sections["CustomSection"] == null)
        {
            customSection = new CustomSection();
            config.Sections.Add("CustomSection2", customSection);
            customSection.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
' Create a custom section.
Shared Sub CreateSection()
    Try
        Dim customSection As CustomSection

        ' Get the current configuration file.
        Dim config As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

        ' Create the section entry  
        ' in the <configSections> and the 
        ' related target section in <configuration>.
        ' Since the config file already has "CustomSection",
        ' call this one "CustomSection2".
        If config.Sections("CustomSection") Is Nothing Then
            customSection = New CustomSection()
            config.Sections.Add("CustomSection", customSection)
            customSection.SectionInformation.ForceSave = True
            config.Save(ConfigurationSaveMode.Full)
        End If
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try
End Sub

注釈

場合は、単純なConfigurationElementなど、CustomSection次の例に示すように、ConfigurationPropertyオブジェクトなどの属性を表すfileNameします。In the case of a simple ConfigurationElement, such as the CustomSection shown in the next example, the ConfigurationProperty objects represent attributes such as fileName.

インスタンスのサブセクションでは、格納しているセクションなどのより複雑な構成要素の場合authenticationConfigurationPropertyオブジェクトが表すことができますConfigurationElementオブジェクトおよび属性。In the case of more complex configuration elements such as a section containing subsections, for instance authentication, the ConfigurationProperty objects can represent ConfigurationElement objects as well as attributes.

ConfigurationPropertyCollectionクラスのコレクションを表す、ConfigurationPropertyいずれかの属性をできるオブジェクトまたはConfigurationElement構成要素のオブジェクト。The ConfigurationPropertyCollection class represents the collection of the ConfigurationProperty objects that can be either attributes or ConfigurationElement objects of a configuration element.

ConfigurationPropertyクラスは、個々 の構成設定を表します。The ConfigurationProperty class represents an individual configuration setting. このクラスを使用すると、取得、または名前、型、および特定の構成のエンティティ (属性または要素) の既定値を設定し、属性が必要ですしは、要素のキーです。 または、既定要素のコレクションを表すかどうかを指定できます。This class allows you to get or set the name, type, and default value for a particular configuration entity (attribute or element) and specify whether the attribute is required, is an element key, or represents a default element collection.

注意 (継承者)

すべてConfigurationElementオブジェクトを作成、内部ConfigurationPropertyCollectionのコレクションConfigurationProperty要素の属性または子要素のコレクションを表すオブジェクト。Every ConfigurationElement object creates an internal ConfigurationPropertyCollection collection of ConfigurationProperty objects that represents either the element attributes or a collection of child elements.

カスタマイズが不可能な情報と機能に含まれる、ElementInformationオブジェクトによって提供される、ElementInformationプロパティ。Non-customizable information and functionality is contained by an ElementInformation object provided by the ElementInformation property.

プログラムまたは宣言 (属性) のコーディング モデルを使用して、カスタム構成要素を作成することができます。You can use a programmatic or a declarative (attributed) coding model to create a custom configuration element.

-プログラムによるモデル。- Programmatic Model. このモデルでは、各要素の属性を取得またはその値を設定し、基になる内部プロパティ バッグに追加のプロパティを作成することが必要なConfigurationElement基本クラス。This model requires that you create a property for each element attribute to get and/or set its value and add it to the internal property bag of the underlying ConfigurationElement base class.

-宣言型モデル。- Declarative Model. この単純なモデルとも呼ばれる属性付きのモデル プロパティを使用して要素の属性を定義し、属性で装飾します。This simpler model, also called attributed model, allows you to define an element attribute by using a property and decorate it with attributes. これらの属性は、プロパティの型とその既定値について ASP.NET 構成システムに指示します。These attributes instruct the ASP.NET configuration system about the property types and their default values. リフレクションによって取得されたこの情報は、ASP.NET 構成システムが要素のプロパティ オブジェクトを作成し、必要な初期化を実行します。With this information, obtained through reflection, the ASP.NET configuration system creates the element property objects for you and performs the required initialization.

コンストラクター

ConfigurationProperty(String, Type) ConfigurationProperty(String, Type) ConfigurationProperty(String, Type) ConfigurationProperty(String, Type)

ConfigurationProperty クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationProperty class.

ConfigurationProperty(String, Type, Object) ConfigurationProperty(String, Type, Object) ConfigurationProperty(String, Type, Object) ConfigurationProperty(String, Type, Object)

ConfigurationProperty クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationProperty class.

ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions)

ConfigurationProperty クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationProperty class.

ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions)

ConfigurationProperty クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationProperty class.

ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String) ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String)

ConfigurationProperty クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConfigurationProperty class.

プロパティ

Converter Converter Converter Converter

構成ファイルへの書き込みを目的として、この TypeConverter を XML 表現に変換するために使用する ConfigurationProperty を取得します。Gets the TypeConverter used to convert this ConfigurationProperty into an XML representation for writing to the configuration file.

DefaultValue DefaultValue DefaultValue DefaultValue

この ConfigurationProperty プロパティの既定値を取得します。Gets the default value for this ConfigurationProperty property.

Description Description Description Description

ConfigurationProperty に関連付けられている説明を取得します。Gets the description associated with the ConfigurationProperty.

IsAssemblyStringTransformationRequired IsAssemblyStringTransformationRequired IsAssemblyStringTransformationRequired IsAssemblyStringTransformationRequired

以前のバージョンの .NET Framework.NET Framework 用に構成プロパティのアセンブリ名をシリアル化する場合に、アセンブリ名の変換が必要かどうかを示します。Indicates whether the assembly name for the configuration property requires transformation when it is serialized for an earlier version of the .NET Framework.NET Framework.

IsDefaultCollection IsDefaultCollection IsDefaultCollection IsDefaultCollection

プロパティが要素の既定のコレクションであるかどうかを示す値を取得します。Gets a value that indicates whether the property is the default collection of an element.

IsKey IsKey IsKey IsKey

この ConfigurationProperty が、格納する側の ConfigurationElement オブジェクトのキーかどうかを示す値を取得します。Gets a value indicating whether this ConfigurationProperty is the key for the containing ConfigurationElement object.

IsRequired IsRequired IsRequired IsRequired

この ConfigurationProperty が必要かどうかを示す値を取得します。Gets a value indicating whether this ConfigurationProperty is required.

IsTypeStringTransformationRequired IsTypeStringTransformationRequired IsTypeStringTransformationRequired IsTypeStringTransformationRequired

以前のバージョンの .NET Framework.NET Framework 用に構成プロパティの型名をシリアル化する場合に、型名の変換が必要かどうかを示します。Indicates whether the type name for the configuration property requires transformation when it is serialized for an earlier version of the .NET Framework.NET Framework.

IsVersionCheckRequired IsVersionCheckRequired IsVersionCheckRequired IsVersionCheckRequired

構成プロパティを XML にシリアル化するかどうかを判断するために、シリアル化時に構成プロパティの親構成セクションを照会する必要があるかどうかを示します。Indicates whether the configuration property's parent configuration section is queried at serialization time to determine whether the configuration property should be serialized into XML.

Name Name Name Name

この ConfigurationProperty の名前を取得します。Gets the name of this ConfigurationProperty.

Type Type Type Type

この ConfigurationProperty オブジェクトの型を取得します。Gets the type of this ConfigurationProperty object.

Validator Validator Validator Validator

この ConfigurationValidatorAttribute オブジェクトを検証するために使用する ConfigurationProperty を取得します。Gets the ConfigurationValidatorAttribute, which is used to validate this ConfigurationProperty object.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください