技术开发 频道

在线修改KeyValue配置节


【IT168技术文档】

  web.config中有一些自定义keyvalue配置节,想要在线修改,找了半天没找到现成的,自己写了一个:

  就是类似这样的配置节:
<system.framework> <add key="SystemFramework.Tracing.Enabled" value="True" /> <add key="SystemFramework.Tracing.TraceLevel" value="4" /> </system.framework>
  写了4个类:
  配置项:NameValueConfigurationItem
public sealed class NameValueConfigurationItem : System.Configuration.ConfigurationElement { private static ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection(); private static readonly ConfigurationProperty _value = new ConfigurationProperty("value", typeof(string), string.Empty, ConfigurationPropertyOptions.IsRequired); private static readonly ConfigurationProperty _key = new ConfigurationProperty("key", typeof(string), string.Empty, ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired); static NameValueConfigurationItem() { _properties.Add(_key); _properties.Add(_value); } internal NameValueConfigurationItem() { } public NameValueConfigurationItem(string key, string value) { base[_key] = key; base[_value] = value; } [ConfigurationProperty("value", IsRequired = true)] public string Value { get { return (string)base[_value]; } } protected override ConfigurationPropertyCollection Properties { get { return _properties; } } [ConfigurationProperty("key", IsRequired = true, IsKey = true)] public string Key { get { return (string)base[_key]; } } }

0
相关文章