다음을 통해 공유


ConfigurationBuilder 클래스

정의

사용자 지정 구성 작성기 구현에서 확장할 기본 클래스를 나타냅니다.

public ref class ConfigurationBuilder abstract : System::Configuration::Provider::ProviderBase
public abstract class ConfigurationBuilder : System.Configuration.Provider.ProviderBase
type ConfigurationBuilder = class
    inherit ProviderBase
Public MustInherit Class ConfigurationBuilder
Inherits ProviderBase
상속
ConfigurationBuilder

예제

다음 예제에서는 간단한 ConfigurationBuilder를 구현하여 환경 변수를 읽는 방법을 보여 줍니다.

using System;
using System.Configuration;
using System.Xml;

namespace Samples.AspNet.Config
{

   public class SampleConfigurationBuilder : ConfigurationBuilder
    {

        public override XmlNode ProcessRawXml(XmlNode rawXml) 
        {

            string rawXmlString = rawXml.OuterXml;

            if (String.IsNullOrEmpty(rawXmlString)) {
                return rawXml;
            }

            rawXmlString = Environment.ExpandEnvironmentVariables(rawXmlString);

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.LoadXml(rawXmlString);
            return doc.DocumentElement;
        }

        public override ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection) 
            => configSection;
    }
}
Imports System.Configuration
Imports System.Xml

Public Class SampleConfigurationBuilder : Inherits ConfigurationBuilder

    Public Overrides Function ProcessRawXml(rawXml As XmlNode)  As XmlNode

        Dim rawXmlString As String = rawXml.OuterXml

        If String.IsNullOrEmpty(rawXmlString) Then
            Return rawXml
        End If

        rawXmlString = Environment.ExpandEnvironmentVariables(rawXmlString)

        Dim doc As New XmlDocument()
        doc.PreserveWhitespace = True
        doc.LoadXml(rawXmlString)
        Return doc.DocumentElement
    End Function

    Public Overrides Function ProcessConfigurationSection(configSection As ConfigurationSection)  As ConfigurationSection
       Return configSection
    End Function

End Class

다음 예제는 이전 예제에 적용되는 구성 파일의 발췌입니다. 이렇게 하면 환경 변수가 appSettings 구성에 적용되고 해당 값을 다음에서 ConfigurationManager.AppSettings사용할 수 있습니다.

<!-- To declare and use Configuration Builders in your configuration chain, update your app.config or web.config file as follows:  -->

<configSections>
  <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>
</configSections>

<configBuilders>
  <builders>
    <add name="SampleConfigurationBuilder" type="CustomConfigBuilders.MyConfigBuilder, CustomConfigBuilders" />
  </builders>
</configBuilders>

<!-- To apply Configuration Builders to a configuration section, use the 'configBuilders' tag as follows:  -->
<appSettings configBuilders="SampleConfigurationBuilder">
  <add key="COMPUTERNAME" value="Will Be Replaced by EnvironmentVariable" />
</appSettings>

설명

이 클래스에서 파생되어 표준 ConfigurationManager API를 사용하여 .NET Framework 애플리케이션에서 사용하려는 외부 원본에서 구성을 읽습니다.

생성자

Name Description
ConfigurationBuilder()

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

속성

Name Description
Description

관리 도구 또는 기타 UI(사용자 인터페이스)에 표시하기에 적합한 짧고 친숙한 설명을 가져옵니다.

(다음에서 상속됨 ProviderBase)
Name

구성 중에 공급자를 참조하는 데 사용되는 이름을 가져옵니다.

(다음에서 상속됨 ProviderBase)

메서드

Name Description
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

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

기본 해시 함수로 사용됩니다.

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

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

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

구성 작성기를 초기화합니다.

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

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

(다음에서 상속됨 Object)
ProcessConfigurationSection(ConfigurationSection)

구성 시스템에서 개체를 ConfigurationSection 수락하고 추가 사용을 위해 수정된 개체 또는 새 ConfigurationSection 개체를 반환합니다.

ProcessRawXml(XmlNode)

XmlNode 구성 파일에서 원시 구성 섹션을 나타내는 것을 허용하고 추가 사용을 위해 수정된 항목 또는 새 XmlNode 항목을 반환합니다.

ToString()

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

(다음에서 상속됨 Object)

적용 대상