ConfigurationBuilder Klasse
Definition
Stellt die Basisklasse dar, die durch benutzerdefinierte Konfigurationsgeneratorimplementierungen erweitert werden soll.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
- Vererbung
Beispiele
Im folgenden Beispiel wird gezeigt, wie ein einfacher configurationbuilder zum Lesen von Umgebungsvariablen implementiert wird: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
Das folgende Beispiel ist ein Auszug aus der Konfigurationsdatei, die für das vorherige Beispiel gilt.The following example is an excerpt of the configuration file as it applies to the previous example. Dies wendet Umgebungsvariablen auf die AppSettings-Konfiguration an und macht diese Werte unter verfügbar ConfigurationManager.AppSettings .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>
Hinweise
Leiten Sie von dieser Klasse ab, um die Konfiguration aus einer externen Quelle zu lesen, die Sie in Ihrer .NET Framework Anwendung mit der Standard-API verwenden möchten ConfigurationManager .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. Configurationbuilder sind auf NuGet.org zum Lesen aus Umgebungsvariablen, Azure Key Vault und einer Reihe anderer Quellen verfügbar.ConfigurationBuilders are available on NuGet.org to read from environment variables, Azure key vault, and a number of other sources.
Mehrere Implementierungen von configurationbuilder sind über NuGet.org verfügbar:Several implementations of ConfigurationBuilders are available from NuGet.org:
- Umgebungskonfigurations -Generator : liest aus Umgebungsvariablen.EnvironmentConfigBuilder - Read from environment variables.
- Azurekeyvaultconfigbuilder -Lesevorgang aus Azure Key Vault.AzureKeyVaultConfigBuilder - Read from Azure Key Vault.
- Usersecretionconfigbuilder : liest aus einer usersecrets-Datei auf dem Datenträger, ähnlich wie die ASP.net Core Funktionen.UserSecretsConfigBuilder - Read from a usersecrets file on disk, similar to the ASP.NET Core functionality.
- Simplejsonconfigbuilder : liest aus einer JSON-Datei.SimpleJsonConfigBuilder - Read from a JSON file.
Konstruktoren
ConfigurationBuilder() |
Initialisiert eine neue Instanz der ConfigurationBuilder-Klasse.Initializes a new instance of the ConfigurationBuilder class. |
Eigenschaften
Description |
Ruft eine kurze, benutzerfreundliche Beschreibung ab, die für die Anzeige in Verwaltungstools oder anderen Benutzeroberflächen geeignet ist.Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs). (Geerbt von ProviderBase) |
Name |
Ruft den Anzeigennamen ab, der verwendet wird, um während der Konfiguration auf den Anbieter zu verweisen.Gets the friendly name used to refer to the provider during configuration. (Geerbt von ProviderBase) |
Methoden
Equals(Object) |
Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object. (Geerbt von Object) |
GetHashCode() |
Fungiert als Standardhashfunktion.Serves as the default hash function. (Geerbt von Object) |
GetType() |
Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance. (Geerbt von Object) |
Initialize(String, NameValueCollection) |
Initialisiert den Konfigurations-Generator.Initializes the configuration builder. (Geerbt von ProviderBase) |
MemberwiseClone() |
Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object. (Geerbt von Object) |
ProcessConfigurationSection(ConfigurationSection) |
Nimmt ein ConfigurationSection-Objekt vom Konfigurationssystem an und gibt ein modifiziertes oder neues ConfigurationSection-Objekt für den weiteren Gebrauch zurück.Accepts a ConfigurationSection object from the configuration system and returns a modified or new ConfigurationSection object for further use. |
ProcessRawXml(XmlNode) |
Akzeptiert einen XmlNode, der den rohen Konfigurationsabschnitt aus einer Konfigurationsdatei darstellt und einen veränderten oder neuen XmlNode für den weiteren Gebrauch zurückgibt.Accepts an XmlNode representing the raw configuration section from a config file and returns a modified or new XmlNode for further use. |
ToString() |
Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object. (Geerbt von Object) |