다음을 통해 공유


ConfigurationSection 클래스

정의

구성 파일 내의 섹션을 나타냅니다.

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
상속
ConfigurationSection
파생

예제

다음 예제에서는 프로그래밍 방식으로 사용자 지정 섹션을 구현하는 방법을 보여 줍니다.

특성 모델을 사용하여 구현된 사용자 지정 섹션을 구현하고 사용하는 방법을 보여 주는 전체 예제는 다음을 참조하세요 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

다음 예제는 이전 예제에 적용되는 구성 파일의 발췌입니다.

<?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 사용하여 사용자 지정 섹션 형식을 구현합니다. 사용자 지정 구성 섹션에 ConfigurationSection 대한 사용자 지정 처리 및 프로그래밍 방식 액세스를 제공하도록 클래스를 확장합니다.

섹션은 해당 처리 형식을 요소의 항목에 등록합니다 configSections . 예를 들어 예제 섹션에 표시된 구성 파일 발췌를 참조하세요.

메모

이전 버전의 .NET Framework에서는 구성 섹션 처리기를 사용하여 구성 설정을 프로그래밍 방식으로 변경했습니다. 이제 모든 기본 구성 섹션은 클래스를 확장하는 ConfigurationSection 클래스로 표시됩니다.

구현자 참고

프로그래밍 방식 또는 선언적(특성 지정된) 코딩 모델을 사용하여 사용자 지정 구성 섹션을 만들 수 있습니다.

  • 프로그래밍 방식 모델입니다. 이 모델을 사용하려면 각 섹션 특성에 대해 속성을 만들어 해당 값을 가져와서 기본 기본 클래스의 내부 속성 모음에 ConfigurationElement 추가해야 합니다.

  • 선언적 모델입니다. 특성 모델이라고도 하는 이 간단한 모델을 사용하면 속성을 사용하고 특성으로 데코레이팅하여 섹션 특성을 정의할 수 있습니다. 이러한 특성은 속성 형식 및 해당 기본값에 대해 ASP.NET 구성 시스템에 지시합니다. 리플렉션을 통해 얻은 이 정보를 사용하여 ASP.NET 구성 시스템은 섹션 속성 개체를 만들고 필요한 초기화를 수행합니다.

Configuration 클래스는 구성 파일을 편집하기 위한 프로그래밍 방식 액세스를 허용합니다. 다음과 같이 읽기 또는 쓰기를 위해 이러한 파일에 액세스할 수 있습니다.

  • 읽기. 구성 정보를 사용 GetSection(String) 하거나 GetSectionGroup(String) 읽습니다. 읽는 사용자 또는 프로세스에는 다음 권한이 있어야 합니다.

    • 현재 구성 계층 수준에서 구성 파일에 대한 읽기 권한입니다.

    • 모든 부모 구성 파일에 대한 읽기 권한입니다.

    애플리케이션이 자체 구성에 대한 읽기 전용 액세스가 필요한 경우 웹 애플리케이션의 경우 오버로드된 메서드 또는 GetSection(String) 클라이언트 애플리케이션의 경우 메서드를 사용하는 GetSection 것이 좋습니다.

    이러한 메서드는 현재 애플리케이션에 대해 캐시된 구성 값에 대한 액세스를 제공하며, 클래스보다 성능이 Configuration 향상됩니다.

참고: 매개 변수 path 를 사용하는 path 정적 GetSection 메서드를 사용하는 경우 매개 변수는 코드가 실행 중인 애플리케이션을 참조해야 합니다. 그렇지 않으면 매개 변수가 무시되고 현재 실행 중인 애플리케이션에 대한 구성 정보가 반환됩니다.

  • 쓰기. 메서드 중 Save 하나를 사용하여 구성 정보를 작성합니다. 작성하는 사용자 또는 프로세스에는 다음 권한이 있어야 합니다.

    • 현재 구성 계층 수준에서 구성 파일 및 디렉터리에 대한 쓰기 권한입니다.

    • 모든 구성 파일에 대한 읽기 권한입니다.

생성자

Name Description
ConfigurationSection()

ConfigurationSection 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
CurrentConfiguration

현재 Configuration 인스턴스가 속한 구성 계층 구조를 나타내는 최상위 ConfigurationElement 인스턴스에 대한 참조를 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
ElementInformation

사용자 지정할 수 없는 정보와 ElementInformation 개체의 기능이 포함된 ConfigurationElement 개체를 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
ElementProperty

ConfigurationElementProperty 개체 자체를 나타내는 ConfigurationElement 개체를 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
EvaluationContext

ContextInformation 개체에 대한 ConfigurationElement 개체를 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
HasContext

CurrentConfiguration 속성이 null여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
Item[ConfigurationProperty]

이 구성 요소의 속성 또는 특성을 가져오거나 설정합니다.

(다음에서 상속됨 ConfigurationElement)
Item[String]

이 구성 요소의 속성, 특성 또는 자식 요소를 가져오거나 설정합니다.

(다음에서 상속됨 ConfigurationElement)
LockAllAttributesExcept

잠긴 특성의 컬렉션을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
LockAllElementsExcept

잠긴 요소의 컬렉션을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
LockAttributes

잠긴 특성의 컬렉션을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
LockElements

잠긴 요소의 컬렉션을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
LockItem

요소가 잠겨 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 ConfigurationElement)
Properties

속성의 컬렉션을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
SectionInformation

개체의 SectionInformation 사용자 지정할 수 없는 정보 및 기능을 포함하는 개체를 ConfigurationSection 가져옵니다.

메서드

Name Description
DeserializeElement(XmlReader, Boolean)

구성 파일에서 XML을 읽습니다.

(다음에서 상속됨 ConfigurationElement)
DeserializeSection(XmlReader)

구성 파일에서 XML을 읽습니다.

Equals(Object)

현재 ConfigurationElement 인스턴스를 지정된 개체와 비교합니다.

(다음에서 상속됨 ConfigurationElement)
GetHashCode()

현재 ConfigurationElement 인스턴스를 나타내는 고유 값을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
GetRuntimeObject()

파생 클래스에서 재정의될 때 사용자 지정 개체를 반환합니다.

GetTransformedAssemblyString(String)

지정된 어셈블리 이름의 변환된 버전을 반환합니다.

(다음에서 상속됨 ConfigurationElement)
GetTransformedTypeString(String)

지정된 형식 이름의 변환된 버전을 반환합니다.

(다음에서 상속됨 ConfigurationElement)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
Init()

ConfigurationElement 개체를 초기 상태로 설정합니다.

(다음에서 상속됨 ConfigurationElement)
InitializeDefault()

ConfigurationElement 개체의 기본 값 집합을 초기화하는 데 사용됩니다.

(다음에서 상속됨 ConfigurationElement)
IsModified()

이 구성 요소가 파생 클래스에서 구현될 때 마지막으로 저장되었거나 로드된 이후 수정되었는지 여부를 나타냅니다.

IsReadOnly()

개체가 읽기 전용인지 여부를 ConfigurationElement 나타내는 값을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
ListErrors(IList)

ConfigurationElement 개체 및 모든 하위 요소의 잘못된 속성 오류를 전달된 목록에 추가합니다.

(다음에서 상속됨 ConfigurationElement)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnDeserializeUnrecognizedAttribute(String, String)

역직렬화하는 동안 알 수 없는 특성이 발생하는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

역직렬화하는 동안 알 수 없는 요소가 발생하는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 ConfigurationElement)
OnRequiredPropertyNotFound(String)

필수 속성을 찾을 수 없는 경우 예외를 throw합니다.

(다음에서 상속됨 ConfigurationElement)
PostDeserialize()

역직렬화 후 호출됩니다.

(다음에서 상속됨 ConfigurationElement)
PreSerialize(XmlWriter)

serialization 전에 호출됩니다.

(다음에서 상속됨 ConfigurationElement)
Reset(ConfigurationElement)

잠금 및 속성 컬렉션을 포함하여 개체의 ConfigurationElement 내부 상태를 다시 설정합니다.

(다음에서 상속됨 ConfigurationElement)
ResetModified()

파생 클래스에서 구현될 때 메서드 IsModified() 값을 false 다시 설정합니다.

SerializeElement(XmlWriter, Boolean)

파생 클래스에서 구현될 때 이 구성 요소의 내용을 구성 파일에 씁니다.

(다음에서 상속됨 ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

파일에 쓸 단일 섹션으로 개체의 ConfigurationSection 무중단 뷰를 포함하는 XML 문자열을 만듭니다.

SerializeToXmlElement(XmlWriter, String)

파생 클래스에서 구현될 때 이 구성 요소의 외부 태그를 구성 파일에 씁니다.

(다음에서 상속됨 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

속성을 지정된 값으로 설정합니다.

(다음에서 상속됨 ConfigurationElement)
SetReadOnly()

IsReadOnly() 개체 및 모든 하위 요소의 ConfigurationElement 속성을 설정합니다.

(다음에서 상속됨 ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

구성 개체 계층 구조가 지정된 대상 버전의 .NET Framework에 대해 serialize될 때 지정된 요소를 serialize해야 하는지 여부를 나타냅니다.

ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

구성 개체 계층 구조가 지정된 대상 버전의 .NET Framework에 대해 serialize될 때 지정된 속성을 serialize해야 하는지 여부를 나타냅니다.

ShouldSerializeSectionInTargetVersion(FrameworkName)

구성 개체 계층이 지정된 대상 버전의 .NET Framework에 대해 serialize될 때 현재 ConfigurationSection 인스턴스를 serialize해야 하는지 여부를 나타냅니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

개체를 ConfigurationElement 수정하여 저장해서는 안 되는 모든 값을 제거합니다.

(다음에서 상속됨 ConfigurationElement)

적용 대상

추가 정보