ConfigurationSection 클래스
정의
구성 파일 내의 섹션을 나타냅니다.Represents a section within a configuration file.
public ref class ConfigurationSection abstract : System::Configuration::ConfigurationElement
public abstract class ConfigurationSection : System.Configuration.ConfigurationElement
type ConfigurationSection = class
inherit ConfigurationElement
Public MustInherit Class ConfigurationSection
Inherits ConfigurationElement
- 상속
- 파생
예제
다음 예제에서는 프로그래밍 방식으로 사용자 지정 섹션을 구현 하는 방법을 보여 줍니다.The following example shows how to implement a custom section programmatically.
특성을 사용 하는 모델을 사용 하 여 구현 된 사용자 지정 섹션을 구현 하 고 사용 하는 방법을 보여 주는 전체 예제는를 참조 하십시오 ConfigurationElement .For a complete example that shows how to implement and use a custom section implemented using the attributed model, see ConfigurationElement.
// Define a custom section.
// The CustomSection type allows to define a custom section
// programmatically.
public sealed class CustomSection :
ConfigurationSection
{
// The collection (property bag) that contains
// the section properties.
private static ConfigurationPropertyCollection _Properties;
// Internal flag to disable
// property setting.
private static bool _ReadOnly;
// The FileName property.
private static readonly ConfigurationProperty _FileName =
new ConfigurationProperty("fileName",
typeof(string),"default.txt",
ConfigurationPropertyOptions.IsRequired);
// The MaxUsers property.
private static readonly ConfigurationProperty _MaxUsers =
new ConfigurationProperty("maxUsers",
typeof(long), (long)1000,
ConfigurationPropertyOptions.None);
// The MaxIdleTime property.
private static readonly ConfigurationProperty _MaxIdleTime =
new ConfigurationProperty("maxIdleTime",
typeof(TimeSpan), TimeSpan.FromMinutes(5),
ConfigurationPropertyOptions.IsRequired);
// CustomSection constructor.
public CustomSection()
{
// Property initialization
_Properties =
new ConfigurationPropertyCollection();
_Properties.Add(_FileName);
_Properties.Add(_MaxUsers);
_Properties.Add(_MaxIdleTime);
}
// This is a key customization.
// It returns the initialized property bag.
protected override ConfigurationPropertyCollection Properties
{
get
{
return _Properties;
}
}
private new bool IsReadOnly
{
get
{
return _ReadOnly;
}
}
// Use this to disable property setting.
private void ThrowIfReadOnly(string propertyName)
{
if (IsReadOnly)
throw new ConfigurationErrorsException(
"The property " + propertyName + " is read only.");
}
// Customizes the use of CustomSection
// by setting _ReadOnly to false.
// Remember you must use it along with ThrowIfReadOnly.
protected override object GetRuntimeObject()
{
// To enable property setting just assign true to
// the following flag.
_ReadOnly = true;
return base.GetRuntimeObject();
}
[StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\",
MinLength = 1, MaxLength = 60)]
public string FileName
{
get
{
return (string)this["fileName"];
}
set
{
// With this you disable the setting.
// Remember that the _ReadOnly flag must
// be set to true in the GetRuntimeObject.
ThrowIfReadOnly("FileName");
this["fileName"] = value;
}
}
[LongValidator(MinValue = 1, MaxValue = 1000000,
ExcludeRange = false)]
public long MaxUsers
{
get
{
return (long)this["maxUsers"];
}
set
{
this["maxUsers"] = value;
}
}
[TimeSpanValidator(MinValueString = "0:0:30",
MaxValueString = "5:00:0",
ExcludeRange = false)]
public TimeSpan MaxIdleTime
{
get
{
return (TimeSpan)this["maxIdleTime"];
}
set
{
this["maxIdleTime"] = value;
}
}
}
' Define a custom section.
' The CustomSection type allows to define a custom section
' programmatically.
NotInheritable Public Class CustomSection
Inherits ConfigurationSection
' The collection (property bag) that contains
' the section properties.
Private Shared _Properties As ConfigurationPropertyCollection
' Internal flag to disable
' property setting.
Private Shared _ReadOnly As Boolean
' The FileName property.
Private Shared _FileName As New ConfigurationProperty( _
"fileName", GetType(String), _
"default.txt", _
ConfigurationPropertyOptions.IsRequired)
' The MaxUsers property.
Private Shared _MaxUsers As New ConfigurationProperty( _
"maxUsers", GetType(Long), _
CType(1000, Long), _
ConfigurationPropertyOptions.None)
' The MaxIdleTime property.
Private Shared _MaxIdleTime As New ConfigurationProperty( _
"maxIdleTime", GetType(TimeSpan), _
TimeSpan.FromMinutes(5), _
ConfigurationPropertyOptions.IsRequired)
' CustomSection constructor.
Public Sub New()
' Property initialization
_Properties = _
New ConfigurationPropertyCollection()
_Properties.Add(_FileName)
_Properties.Add(_MaxUsers)
_Properties.Add(_MaxIdleTime)
End Sub
' This is a key customization.
' It returns the initialized property bag.
Protected Overrides ReadOnly Property Properties() _
As ConfigurationPropertyCollection
Get
Return _Properties
End Get
End Property
Private Shadows ReadOnly Property IsReadOnly() As Boolean
Get
Return _ReadOnly
End Get
End Property
' Use this to disable property setting.
Private Sub ThrowIfReadOnly(propertyName As String)
If IsReadOnly Then
Throw New ConfigurationErrorsException( _
"The property " + propertyName + " is read only.")
End If
End Sub
' Customizes the use of CustomSection
' by setting _ReadOnly to false.
' Remember you must use it along with ThrowIfReadOnly.
Protected Overrides Function GetRuntimeObject() As Object
' To enable property setting just assign true to
' the following flag.
_ReadOnly = True
Return MyBase.GetRuntimeObject()
End Function 'GetRuntimeObject
<StringValidator( _
InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
MinLength:=1, MaxLength:=60)> _
Public Property FileName() As String
Get
Return CStr(Me("fileName"))
End Get
Set(ByVal value As String)
' With this you disable the setting.
' Remember that the _ReadOnly flag must
' be set to true in the GetRuntimeObject.
ThrowIfReadOnly("FileName")
Me("fileName") = 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
<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
End Class
다음 예제에서는 구성 파일의 일부는 앞의 예제에 적용 됩니다.The following example is an excerpt of the configuration file as it applies to the previous example.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="CustomSection" type="Samples.AspNet. CustomSection, CustomConfigurationSection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
</configSections>
<CustomSection fileName="default.txt" maxUsers="1000" maxIdleTime="00:15:00" />
</configuration>
설명
클래스를 사용 하 여 ConfigurationSection 사용자 지정 섹션 형식을 구현 합니다.You use the ConfigurationSection class to implement a custom section type. 클래스를 확장 하 여 사용자 지정 ConfigurationSection 구성 섹션에 대 한 사용자 지정 처리 및 프로그래밍 방식의 액세스를 제공 합니다.Extend the ConfigurationSection class to provide custom handling and programmatic access to custom configuration sections. 사용자 지정 구성 섹션을 사용 하는 방법에 대 한 자세한 내용은 방법: ConfigurationSection을 사용 하 여 사용자 지정 구성 섹션 만들기를 참조 하세요.For information about how use custom configuration sections, see How to: Create Custom Configuration Sections Using ConfigurationSection.
섹션에서는 해당 처리 형식을 요소의 항목에 등록 configSections
합니다.A section registers its handling type with an entry in the configSections
element. 예제를 보려면 예제 섹션에 표시 된 구성 파일 발췌를 참조 하십시오.For an example, see the configuration file excerpt shown in the Example section.
참고
이전 버전의 .NET Framework에서는 구성 섹션 처리기를 사용 하 여 구성 설정을 프로그래밍 방식으로 변경 했습니다.In previous versions of the .NET Framework, configuration section handlers were used to make changes to configuration settings programmatically. 이제 모든 기본 구성 섹션은 클래스를 확장 하는 클래스로 표현 됩니다 ConfigurationSection .Now, all the default configuration sections are represented by classes that extend the ConfigurationSection class.
구현자 참고
프로그래밍 방식이 나 선언적 (특성) 코딩 모델을 사용 하 여 사용자 지정 구성 섹션을 만들 수 있습니다.You can use a programmatic or a declarative (attributed) coding model to create custom configuration sections: -프로그래밍 모델입니다.- Programmatic model. 이 모델에서는 각 section 특성에 대해 속성을 만들어 해당 값을 가져오거나 설정 하 고 기본 기본 클래스의 내부 속성 모음에 추가 해야 합니다 ConfigurationElement .This model requires that for each section attribute you create a property to get or set its value and add it to the internal property bag of the underlying ConfigurationElement base class.
-선언적 모델- Declarative model. 특성이 지정 된 모델이 라고도 하는이 간단한 모델을 사용 하면 속성을 사용 하 여 section 특성을 정의 하 고 특성으로 데코레이팅 할 수 있습니다.This simpler model, also called the attributed model, allows you to define a section attribute by using a property and decorating it with attributes. 이러한 특성은 속성 형식 및 해당 기본값에 대해 ASP.NET 구성 시스템에 지시 합니다.These attributes instruct the ASP.NET configuration system about the property types and their default values. ASP.NET 구성 시스템은 리플렉션을 통해 얻은이 정보를 사용 하 여 section 속성 개체를 만들고 필요한 초기화를 수행 합니다.With this information, obtained through reflection, the ASP.NET configuration system creates the section property objects and performs the required initialization.
Configuration 클래스는 구성 파일 편집에 대 한 프로그래밍 방식의 액세스를 허용 합니다.The Configuration class allows programmatic access for editing configuration files. 이러한 파일을 읽기용 또는 쓰기용 다음과 같이 액세스할 수 있습니다.You can access these files for reading or writing as follows: 읽어.- Reading. 사용할 GetSection(String) 또는 GetSectionGroup(String) 구성 정보를 읽습니다.You use GetSection(String) or GetSectionGroup(String) to read configuration information. Note 사용자나 읽는 프로세스는 다음 권한이 있어야 합니다.Note that the user or process that reads must have the following permissions: -현재 구성 계층 구조 수준에서 구성 파일에서 읽기 권한입니다.- Read permission on the configuration file at the current configuration hierarchy level.
-파일을 읽을 모든 부모에 대 한 권한을 구성 합니다.- Read permissions on all the parent configuration files.
애플리케이션에서 자체 구성에 대 한 읽기 전용 액세스에 필요한 것이 좋습니다 사용 합니다 GetSection 오버 로드 된 웹 애플리케이션의 경우 메서드 또는 GetSection(String) 클라이언트 애플리케이션의 경우 메서드.If your application needs read-only access to its own configuration, it is recommended you use the GetSection overloaded methods in the case of Web applications, or the GetSection(String) method in the case of client applications.
이러한 메서드에 액세스할 수 있는 보다 더 나은 성능을 현재 애플리케이션에 대 한 캐시 된 구성 값에는 Configuration 클래스입니다.These methods provide access to the cached configuration values for the current application, which has better performance than the Configuration class.
정적을 사용 하는 경우 GetSection
사용 하는 메서드를 path
매개 변수는 path
매개 변수는 코드가 실행 되 고이 고, 그렇지 매개 변수는 무시 하는 애플리케이션 및 현재-실행에 대 한 구성 정보를 참조 해야 합니다 애플리케이션에 반환 됩니다.If you use a static GetSection
method that takes a path
parameter, the path
parameter must refer to the application in which the code is running; otherwise, the parameter is ignored and configuration information for the currently-running application is returned.
작성.- Writing. 하나를 사용 하 여 Save 구성 정보를 기록 하는 방법.You use one of the Save methods to write configuration information. Note는 사용자 또는 기록 하는 프로세스는 다음 권한이 있어야 합니다.Note that the user or process that writes must have the following permissions: -구성 파일 및 디렉터리에서 현재 구성 계층 구조 수준에서 권한을 작성 합니다.- Write permission on the configuration file and directory at the current configuration hierarchy level.
-모든 구성 파일에 대 한 권한을 읽습니다.- Read permissions on all the configuration files.
생성자
ConfigurationSection() |
ConfigurationSection 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ConfigurationSection class. |
속성
CurrentConfiguration |
현재 Configuration 인스턴스가 속해 있는 구성 계층 구조를 나타내는 최상위 ConfigurationElement 인스턴스에 대한 참조를 가져옵니다.Gets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to. (다음에서 상속됨 ConfigurationElement) |
ElementInformation |
ElementInformation 개체의 사용자 지정할 수 없는 정보와 기능을 포함하는 ConfigurationElement 개체를 가져옵니다.Gets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object. (다음에서 상속됨 ConfigurationElement) |
ElementProperty |
ConfigurationElementProperty 개체 자체를 나타내는 ConfigurationElement 개체를 가져옵니다.Gets the ConfigurationElementProperty object that represents the ConfigurationElement object itself. (다음에서 상속됨 ConfigurationElement) |
EvaluationContext |
ContextInformation 개체의 ConfigurationElement 개체를 가져옵니다.Gets the ContextInformation object for the ConfigurationElement object. (다음에서 상속됨 ConfigurationElement) |
HasContext |
CurrentConfiguration 속성이 |
Item[ConfigurationProperty] |
이 구성 요소의 속성이나 특성을 가져오거나 설정합니다.Gets or sets a property or attribute of this configuration element. (다음에서 상속됨 ConfigurationElement) |
Item[String] |
이 구성 요소의 속성, 특성 또는 자식 요소를 가져오거나 설정합니다.Gets or sets a property, attribute, or child element of this configuration element. (다음에서 상속됨 ConfigurationElement) |
LockAllAttributesExcept |
잠긴 특성의 컬렉션을 가져옵니다.Gets the collection of locked attributes. (다음에서 상속됨 ConfigurationElement) |
LockAllElementsExcept |
잠긴 요소의 컬렉션을 가져옵니다.Gets the collection of locked elements. (다음에서 상속됨 ConfigurationElement) |
LockAttributes |
잠긴 특성의 컬렉션을 가져옵니다.Gets the collection of locked attributes. (다음에서 상속됨 ConfigurationElement) |
LockElements |
잠긴 요소의 컬렉션을 가져옵니다.Gets the collection of locked elements. (다음에서 상속됨 ConfigurationElement) |
LockItem |
요소가 잠겨 있는지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the element is locked. (다음에서 상속됨 ConfigurationElement) |
Properties |
속성 컬렉션을 가져옵니다.Gets the collection of properties. (다음에서 상속됨 ConfigurationElement) |
SectionInformation |
사용자가 지정할 수 없는 SectionInformation 개체의 정보와 기능을 포함하는 ConfigurationSection 개체를 가져옵니다.Gets a SectionInformation object that contains the non-customizable information and functionality of the ConfigurationSection object. |
메서드
DeserializeElement(XmlReader, Boolean) |
구성 파일에서 XML을 읽습니다.Reads XML from the configuration file. (다음에서 상속됨 ConfigurationElement) |
DeserializeSection(XmlReader) |
구성 파일에서 XML을 읽습니다.Reads XML from the configuration file. |
Equals(Object) |
현재 ConfigurationElement 인스턴스를 지정된 개체와 비교합니다.Compares the current ConfigurationElement instance to the specified object. (다음에서 상속됨 ConfigurationElement) |
GetHashCode() |
현재 ConfigurationElement 인스턴스를 나타내는 고유 값을 가져옵니다.Gets a unique value representing the current ConfigurationElement instance. (다음에서 상속됨 ConfigurationElement) |
GetRuntimeObject() |
파생 클래스에서 재정의될 때 사용자 지정 개체를 반환합니다.Returns a custom object when overridden in a derived class. |
GetTransformedAssemblyString(String) |
지정된 어셈블리 이름의 변환된 버전을 반환합니다.Returns the transformed version of the specified assembly name. (다음에서 상속됨 ConfigurationElement) |
GetTransformedTypeString(String) |
지정된 형식 이름의 변환된 버전을 반환합니다.Returns the transformed version of the specified type name. (다음에서 상속됨 ConfigurationElement) |
GetType() |
현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance. (다음에서 상속됨 Object) |
Init() |
ConfigurationElement 개체를 초기 상태로 설정합니다.Sets the ConfigurationElement object to its initial state. (다음에서 상속됨 ConfigurationElement) |
InitializeDefault() |
ConfigurationElement 개체 값의 기본 집합을 초기화하는 데 사용됩니다.Used to initialize a default set of values for the ConfigurationElement object. (다음에서 상속됨 ConfigurationElement) |
IsModified() |
이 구성 요소가 파생 클래스에서 구현되었을 때 마지막으로 저장되거나 로드된 이후 수정되었는지 여부를 나타냅니다.Indicates whether this configuration element has been modified since it was last saved or loaded when implemented in a derived class. |
IsReadOnly() |
ConfigurationElement 개체가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the ConfigurationElement object is read-only. (다음에서 상속됨 ConfigurationElement) |
ListErrors(IList) |
이 ConfigurationElement 개체와 모든 하위 요소의 잘못된 속성 오류를 전달된 목록에 추가합니다.Adds the invalid-property errors in this ConfigurationElement object, and in all subelements, to the passed list. (다음에서 상속됨 ConfigurationElement) |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
OnDeserializeUnrecognizedAttribute(String, String) |
역직렬화하는 동안 알 수 없는 특성을 발견했는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether an unknown attribute is encountered during deserialization. (다음에서 상속됨 ConfigurationElement) |
OnDeserializeUnrecognizedElement(String, XmlReader) |
역직렬화하는 동안 알 수 없는 요소를 발견했는지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether an unknown element is encountered during deserialization. (다음에서 상속됨 ConfigurationElement) |
OnRequiredPropertyNotFound(String) |
필수 속성이 없으면 예외를 throw합니다.Throws an exception when a required property is not found. (다음에서 상속됨 ConfigurationElement) |
PostDeserialize() |
deserialization 후에 호출됩니다.Called after deserialization. (다음에서 상속됨 ConfigurationElement) |
PreSerialize(XmlWriter) |
serialization 전에 호출됩니다.Called before serialization. (다음에서 상속됨 ConfigurationElement) |
Reset(ConfigurationElement) |
잠금 및 속성 컬렉션을 비롯하여 ConfigurationElement 개체의 내부 상태를 다시 설정합니다.Resets the internal state of the ConfigurationElement object, including the locks and the properties collections. (다음에서 상속됨 ConfigurationElement) |
ResetModified() |
파생 클래스에서 구현되는 경우 IsModified() 메서드의 값을 |
SerializeElement(XmlWriter, Boolean) |
파생 클래스에서 구현될 때 구성 요소의 내용을 구성 파일에 씁니다.Writes the contents of this configuration element to the configuration file when implemented in a derived class. (다음에서 상속됨 ConfigurationElement) |
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
ConfigurationSection 개체의 병합되지 않은 뷰가 들어 있는 XML 문자열을 파일에 쓸 단일 섹션으로 만듭니다.Creates an XML string containing an unmerged view of the ConfigurationSection object as a single section to write to a file. |
SerializeToXmlElement(XmlWriter, String) |
파생 클래스에서 구현될 때 구성 요소의 외부 태그를 구성 파일에 씁니다.Writes the outer tags of this configuration element to the configuration file when implemented in a derived class. (다음에서 상속됨 ConfigurationElement) |
SetPropertyValue(ConfigurationProperty, Object, Boolean) |
속성을 지정된 값으로 설정합니다.Sets a property to the specified value. (다음에서 상속됨 ConfigurationElement) |
SetReadOnly() |
IsReadOnly() 개체와 모든 하위 요소에 대한 ConfigurationElement 속성을 설정합니다.Sets the IsReadOnly() property for the ConfigurationElement object and all subelements. (다음에서 상속됨 ConfigurationElement) |
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
지정된 대상 버전의 .NET Framework.NET Framework에 대해 구성 개체 계층 구조가 serialize된 경우 지정된 요소를 serialize할지 여부를 나타냅니다.Indicates whether the specified element should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework.NET Framework. |
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
지정된 대상 버전의 .NET Framework.NET Framework에 대해 구성 개체 계층 구조가 serialize된 경우 지정된 속성을 serialize할지 여부를 나타냅니다.Indicates whether the specified property should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework.NET Framework. |
ShouldSerializeSectionInTargetVersion(FrameworkName) |
지정된 대상 버전의 .NET Framework.NET Framework에 대해 구성 개체 계층 구조가 serialize된 경우 현재 ConfigurationSection 인스턴스를 serialize할지 여부를 나타냅니다.Indicates whether the current ConfigurationSection instance should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework.NET Framework. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object. (다음에서 상속됨 Object) |
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
ConfigurationElement 개체를 수정하여 저장되지 않아야 하는 값을 모두 제거합니다.Modifies the ConfigurationElement object to remove all values that should not be saved. (다음에서 상속됨 ConfigurationElement) |