Represents the base class to be extended by custom configuration builder implementations.
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
The following example shows how to implement a simple ConfigurationBuilder to read Environment variables:
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
The following example is an excerpt of the configuration file as it applies to the previous example. This applies environment variables to the appSettings configuration and makes those values available under 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>
Derive from this class to read configuration from an external source that you would like to consume in your .NET Framework application using the standard ConfigurationManager API. ConfigurationBuilders are available on NuGet.org to read from environment variables, Azure key vault, and a number of other sources.
Several implementations of ConfigurationBuilders are available from NuGet.org:
Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).
(Inherited from ProviderBase) NameGets the friendly name used to refer to the provider during configuration.
(Inherited from ProviderBase) MethodsCollaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4