本文整理汇总了C#中System.Configuration.ConfigurationSection类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationSection类的具体用法?C# ConfigurationSection怎么用?C# ConfigurationSection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationSection类属于System.Configuration命名空间,在下文中一共展示了ConfigurationSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public static void Save(ConfigurationSection configSection)
{
System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.Sections.Remove(configSection.SectionInformation.Name);
configuration.Sections.Add(configSection.SectionInformation.Name, configSection);
configuration.Save();
}
示例2: DoCheckGetSection
/// <summary>
/// Checks whether the result of a call to <see cref="IConfigurationSource.GetSection(string)"/> should be deferred to a subordinate source.<br/>
/// If the call should be deferred, returns the <see cref="ConfigurationSection"/> intance from the approriate source.<br/>
/// If the call should not be deferred returns <paramref name="configurationSection"/>.
/// </summary>
/// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
/// <param name="configurationSection">The section that was retrieved from configuration.</param>
/// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
/// <seealso cref="IConfigurationSource.GetSection(string)"/>
/// <exception cref="ConfigurationSourceErrorsException">Thrown if a section does not exist in a registered source.</exception>
protected override ConfigurationSection DoCheckGetSection(string sectionName, ConfigurationSection configurationSection)
{
string sourceNameForSection;
if (!sectionRedirectTable.TryGetValue(sectionName, out sourceNameForSection))
{
return configurationSection;
}
//if no source is specified we can return.
if (string.IsNullOrEmpty(sourceNameForSection))
{
return configurationSection;
}
IConfigurationSource subordinateSource = GetSubordinateSource(sourceNameForSection);
EnsurePropagatingSectionChangeEvents(sourceNameForSection, sectionName);
var section = subordinateSource.GetSection(sectionName);
if (section == null)
throw new ConfigurationSourceErrorsException(
string.Format(CultureInfo.CurrentCulture,
Resources.ExceptionRedirectedConfigurationSectionNotFound,
sectionName,
sourceNameForSection));
return section;
}
示例3: OverrideWithGroupPolicies
public override bool OverrideWithGroupPolicies(ConfigurationSection configurationObject,
bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey)
{
called = true;
this.configurationObject = configurationObject;
this.readGroupPolicies = readGroupPolicies;
this.machineKey = machineKey;
this.userKey = userKey;
IRegistryKey policyKey = GetPolicyKey(machineKey, userKey);
if (policyKey != null)
{
if (!policyKey.GetBoolValue(PolicyValueName).Value)
{
return false;
}
TestsConfigurationSection section = configurationObject as TestsConfigurationSection;
if (section != null)
{
try
{
section.Value = policyKey.GetStringValue(ValuePropertyName);
}
catch (RegistryAccessException)
{ }
}
}
return true;
}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:31,代码来源:MockConfigurationSectionManageabilityProviderBase.cs
示例4: Add
/// <summary>
/// Adds a <see cref="ConfigurationSection"/> to the configuration source location specified by
/// <paramref name="saveParameter"/> and saves the configuration source.
/// </summary>
/// <remarks>
/// If a configuration section with the specified name already exists in the location specified by
/// <paramref name="saveParameter"/> it will be replaced.
/// </remarks>
/// <param name="saveParameter">The <see cref="IConfigurationParameter"/> that represents the location where
/// to save the updated configuration. Must be an instance of <see cref="FileConfigurationParameter"/>.</param>
/// <param name="sectionName">The name by which the <paramref name="configurationSection"/> should be added.</param>
/// <param name="configurationSection">The configuration section to add.</param>
public void Add(IConfigurationParameter saveParameter, string sectionName, ConfigurationSection configurationSection)
{
FileConfigurationParameter parameter = saveParameter as FileConfigurationParameter;
if (null == parameter) throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionUnexpectedType, typeof(FileConfigurationParameter).Name), "saveParameter");
Save(parameter.FileName, sectionName, configurationSection);
}
示例5: GetSectionRelativeFile
/// <summary>
/// 得到Section的相关文件
/// </summary>
/// <param name="config"></param>
/// <param name="section"></param>
/// <returns></returns>
public static string GetSectionRelativeFile(this System.Configuration.Configuration config, ConfigurationSection section)
{
string result = string.Empty;
if (config != null && section != null)
{
string configSource = section.SectionInformation.ConfigSource;
if (configSource.IsNullOrEmpty())
{
ConfigurationSection sectionInConfig = GetSectionRecursively(config, section.SectionInformation.SectionName);
if (sectionInConfig != null)
configSource = sectionInConfig.SectionInformation.ConfigSource;
}
if (configSource.IsNotEmpty() && config.FilePath.IsNotEmpty())
{
string configDir = Path.GetDirectoryName(config.FilePath);
result = Path.Combine(configDir, configSource);
}
}
return result;
}
示例6: Add
public void Add(string sectionName, ConfigurationSection configurationSection)
{
if (CompositeConfigurationSource.CheckAddSection(sectionName, configurationSection)) return;
contents.Add(sectionName, configurationSection);
}
示例7: OpenCore
/// <summary>
/// Opens the security settings configuration section, builds the design time nodes and adds them to the application node.
/// </summary>
/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
/// <param name="rootNode">The root node of the application.</param>
/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
{
if (null != section)
{
rootNode.AddNode(new SecuritySettingsNodeBuilder(serviceProvider, (SecuritySettings)section).Build());
}
}
示例8: CheckGetSection
/// <summary>
/// Checks whether a call to <see cref="IConfigurationSource.GetSection(string)"/> should be extended.<br/>
/// If the call should be extended performs the extended behavior and returns the modified <see cref="ConfigurationSection"/> intance.<br/>
/// If the call should not be extended returns <paramref name="configurationSection"/>.
/// </summary>
/// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
/// <param name="configurationSection">The section that was retrieved from configuration.</param>
/// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
/// <seealso cref="IConfigurationSource.GetSection(string)"/>
public ConfigurationSection CheckGetSection(string sectionName, ConfigurationSection configurationSection)
{
//design time managers occasionally call with sectionName == "".
//this should be fixed in designtime managers
if (string.IsNullOrEmpty(sectionName)) // throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "sectionName");
{
return configurationSection;
}
//if we are already loading we should return.
if (RecursionLock.InsideHandlerOperation)
{
return configurationSection;
}
//this is a section we depend on internally
if (sectionName == ConfigurationSourceSection.SectionName)
{
return configurationSection;
}
lock (LockObject)
{
using (new RecursionLock())
{
EnsureInitialized();
return DoCheckGetSection(sectionName, configurationSection);
}
}
}
示例9: SaveSection
private static void SaveSection(System.Configuration.Configuration config, ConfigurationSection section)
{
// Save the section.
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
示例10: Apply
/// <inheritdoc />
public void Apply(ConfigurationSection section)
{
Ensure.ArgumentNotNull(section, "section");
Ensure.ArgumentTypeAssignableFrom(typeof(CustomConfigurationSection), section.GetType(), "section");
this.section = (CustomConfigurationSection)section;
}
示例11: Clone
///<summary>
/// Clones a <see cref="ConfigurationSection"/>
///</summary>
///<param name="section">The <see cref="ConfigurationSection"/> to clone.</param>
///<returns>A new, cloned <see cref="ConfigurationSection"/>.</returns>
public ConfigurationSection Clone(ConfigurationSection section)
{
if (section == null) throw new ArgumentNullException("section");
var clonedSection = (ConfigurationSection)Activator.CreateInstance(section.GetType());
return (ConfigurationSection)CloneElement(section, clonedSection);
}
示例12: OpenCore
/// <summary>
/// Opens the instrumenation section, builds the design time nodes and adds them to the application node.
/// </summary>
/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
/// <param name="rootNode">The root node of the application.</param>
/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
{
if (null != section)
{
rootNode.AddNode(new InstrumentationNode((InstrumentationConfigurationSection)section));
}
}
示例13: Add
// Add a new section to the collection. This will result in a new declaration and definition.
// It is an error if the section already exists.
public void Add(string name, ConfigurationSection section)
{
VerifyIsAttachedToConfigRecord();
_configRecord.AddConfigurationSection(_configSectionGroup.SectionGroupName, name, section);
BaseAdd(name, name);
}
示例14: PropertyFilter
/// <summary>
/// Set Property Filters constructor via ConfigurationSection from configuration file
/// </summary>
/// <param name="section">ConfigurationSection from configuration file</param>
public PropertyFilter(ConfigurationSection section) : this()
{
//initialize fields
if (section != null)
{
foreach (KeyValueConfigurationElement keyVal in ((AppSettingsSection)section).Settings)
{
if (!string.IsNullOrEmpty(keyVal.Value))
{
switch (keyVal.Key.ToUpper())
{
case "EQUALTO":
EqualTo.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
break;
case "STARTWITH":
StartWith.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
break;
case "CONTAIN":
Contain.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
break;
case "PROPERTYSETSEQUALTO":
PropertySetsEqualTo.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
break;
default:
#if DEBUG
Debug.WriteLine(string.Format("Invalid Key - {0}", keyVal.Key.ToUpper()));
#endif
break;
}
}
}
}
}
示例15: OpenCore
/// <summary>
/// Opens the oracle connection configuration section, builds the design time nodes and adds them to the application node.
/// </summary>
/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
/// <param name="rootNode">The root node of the application.</param>
/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
{
if (null != section)
{
OracleConnectionNodeBuilder builder = new OracleConnectionNodeBuilder(serviceProvider, (OracleConnectionSettings)section);
builder.Build();
}
}