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 확장하여 사용자 지정 구성 섹션에 대한 사용자 지정 처리 및 프로그래밍 방식 액세스를 제공합니다. 사용자 지정 구성 섹션을 사용하는 방법에 대한 자세한 내용은 방법: ConfigurationSection을 사용하여 사용자 지정 구성 섹션 만들기를 참조하세요.

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

참고

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

구현자 참고

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

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

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

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

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

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

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

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

    이러한 메서드에 액세스할 수 있는 보다 더 나은 성능을 현재 애플리케이션에 대 한 캐시 된 구성 값에는 Configuration 클래스입니다.

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

  • 쓰기. 하나를 사용 하 여 Save 구성 정보를 기록 하는 방법. Note는 사용자 또는 기록 하는 프로세스는 다음 권한이 있어야 합니다.

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

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

생성자

ConfigurationSection()

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

속성

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 개체를 가져옵니다.

메서드

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()

deserialization 후에 호출됩니다.

(다음에서 상속됨 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 대해 직렬화될 때 현재 ConfigurationSection instance serialize해야 하는지 여부를 나타냅니다.

ToString()

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

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

ConfigurationElement 개체를 수정하여 저장되지 않아야 하는 값을 모두 제거합니다.

(다음에서 상속됨 ConfigurationElement)

적용 대상

추가 정보