ConfigurationProperty 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
구성 요소의 특성 또는 자식입니다. 이 클래스는 상속할 수 없습니다.
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다.
public ref class ConfigurationProperty sealed
public sealed class ConfigurationProperty
type ConfigurationProperty = class
Public NotInheritable Class ConfigurationProperty
- 상속
-
ConfigurationProperty
예제
- 다음 코드 예제에서는 사용자 지정 섹션을 ConfigurationProperty 만들 때 사용하는 방법을 보여줍니다.
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.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
다음은 이전 예제의 코드에서 사용한 구성 파일의 발췌입니다.
<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>
다음 예제에서는 코드에서 이전 섹션을 만드는 방법을 보여줍니다.
// 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특성을 나타냅니다.
예를 들어 authenticationConfigurationProperty 하위 섹션을 포함하는 섹션과 같은 더 복잡한 구성 요소의 경우 개체는 특성뿐만 아니라 개체를 나타낼 ConfigurationElement 수 있습니다.
클래스는 ConfigurationPropertyCollection 구성 요소의 ConfigurationProperty 특성 또는 ConfigurationElement 개체일 수 있는 개체의 컬렉션을 나타냅니다.
클래스는 ConfigurationProperty 개별 구성 설정을 나타냅니다. 이 클래스를 사용하면 특정 구성 엔터티(특성 또는 요소)의 이름, 형식 및 기본값을 가져와서 설정하고 특성이 필요한지, 요소 키인지 또는 기본 요소 컬렉션을 나타내는지 지정할 수 있습니다.
상속자 참고
모든 ConfigurationElement 개체는 요소 특성 또는 자식 요소 컬렉션을 ConfigurationPropertyCollection 나타내는 개체의 내부 ConfigurationProperty 컬렉션을 만듭니다.
사용자 지정할 수 없는 정보 및 기능은 속성에서 ElementInformation 제공하는 개체에 의해 ElementInformation 포함됩니다.
프로그래밍 방식 또는 선언적(특성 지정) 코딩 모델을 사용하여 사용자 지정 구성 요소를 만들 수 있습니다.
프로그래밍 방식 모델입니다. 이 모델을 사용하려면 각 요소 특성에 대한 속성을 만들어 해당 값을 가져와서 설정하고 기본 ConfigurationElement 기본 클래스의 내부 속성 모음에 추가해야 합니다.
선언적 모델입니다. 특성 모델이라고도 하는 이 더 간단한 모델을 사용하면 속성을 사용하여 요소 특성을 정의하고 특성으로 데코레이트할 수 있습니다. 이러한 특성은 속성 형식 및 해당 기본값에 대해 ASP.NET 구성 시스템에 지시합니다. 리플렉션을 통해 얻은 이 정보를 사용하여 ASP.NET 구성 시스템은 자동으로 요소 속성 개체를 만들고 필요한 초기화를 수행합니다.
생성자
| Name | Description |
|---|---|
| ConfigurationProperty(String, Type, Object, ConfigurationPropertyOptions) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. ConfigurationProperty 클래스의 새 인스턴스를 초기화합니다. |
| ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions, String) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. ConfigurationProperty 클래스의 새 인스턴스를 초기화합니다. |
| ConfigurationProperty(String, Type, Object, TypeConverter, ConfigurationValidatorBase, ConfigurationPropertyOptions) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. ConfigurationProperty 클래스의 새 인스턴스를 초기화합니다. |
| ConfigurationProperty(String, Type, Object) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. ConfigurationProperty 클래스의 새 인스턴스를 초기화합니다. |
| ConfigurationProperty(String, Type) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. ConfigurationProperty 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Converter |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. TypeConverter 구성 파일에 쓰기 위한 XML 표현으로 변환 ConfigurationProperty 하는 데 사용되는 항목을 가져옵니다. |
| DefaultValue |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 이 ConfigurationProperty 속성의 기본값을 가져옵니다. |
| Description |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 에 연결된 ConfigurationProperty설명을 가져옵니다. |
| IsAssemblyStringTransformationRequired |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 구성 속성의 어셈블리 이름이 이전 버전의 .NET Framework에 대해 serialize될 때 변환이 필요한지 여부를 나타냅니다. |
| IsDefaultCollection |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 속성이 요소의 기본 컬렉션인지 여부를 나타내는 값을 가져옵니다. |
| IsKey |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 포함하는 ConfigurationProperty 개체의 키인지 여부를 ConfigurationElement 나타내는 값을 가져옵니다. |
| IsRequired |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 필요한지 여부를 ConfigurationProperty 나타내는 값을 가져옵니다. |
| IsTypeStringTransformationRequired |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 구성 속성의 형식 이름이 이전 버전의 .NET Framework에 대해 serialize될 때 변환이 필요한지 여부를 나타냅니다. |
| IsVersionCheckRequired |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 구성 속성의 부모 구성 섹션을 serialization 시간에 쿼리하여 구성 속성을 XML로 serialize해야 하는지 여부를 나타냅니다. |
| Name |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 이 ConfigurationProperty이름을 가져옵니다. |
| Type |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 이 ConfigurationProperty 개체의 형식을 가져옵니다. |
| Validator |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 이 ConfigurationValidatorAttribute 개체의 ConfigurationProperty유효성을 검사하는 데 사용되는 을 가져옵니다. |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
이 API는 제품 인프라를 지원하며 코드에서 직접 사용되지 않습니다. 현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |