C# 在自定义配置节中添加新集合

C# 在自定义配置节中添加新集合,c#,configuration,C#,Configuration,我有一个自定义配置部分,我需要向其中添加一个新的NameValue内容 这是层次结构 -organizationConfigurations |-organizationConfigSelector |-specificConfigurations |-organizationConfig 现在我需要向organizationConfig添加一个名为skipLanguages的元素,这只是一个简单的集合元素,它只包含字符串。下面是XML示例 <?xml version="1.0

我有一个自定义配置部分,我需要向其中添加一个新的NameValue内容

这是层次结构

 -organizationConfigurations
 |-organizationConfigSelector
 |-specificConfigurations
  |-organizationConfig
现在我需要向organizationConfig添加一个名为skipLanguages的元素,这只是一个简单的集合元素,它只包含字符串。下面是XML示例

<?xml version="1.0" encoding="utf-8" ?>

目前,我添加了SkipLanguages作为名称-值对,值作为分号分隔的字符串,其中包含要隐藏/阻止的语言。显然,这一点非常有效,也被铅所接受。所以,我用我自己的答案来完成这个问题。

目前,我添加了SkipLanguages作为名称-值对,值作为分号分隔的字符串,其中包含要隐藏/阻止的语言
<matcher type="Host" match="HORNET" serviceName="config-hornet"/>
<matcher type="Parameter" match="VTDEV" serviceName="config-test-server"/>
<organizationConfig name="config-hornet">
  <add name="Organization_Identifier" value="SampleOrg"/>

  <add name="Allow_SelfRegistration" value="true"/>

  <add name="ApplicationSelector" value=""/>
  <add name="RegistrationSelector" value=""/>

  <add name="EnrollPinValidity" value="00.00:01:00"/>
  <add name="EnrollIncoming" value="0123456789"/>
  <add name="EnrollOutgoing" value="PIN"/>

  <add name="EnrollmentLockout" value="00.00:01:00"/>
  <add name="PinLockout" value="00.00:00:30"/>

  <skipLanguages>
    <add name="en"/>
    <add name="ur-UR" />
  </skipLanguages>

  <add name="Menu_Hide_Details" value="false"/>
  <add name="International_Format_Example" value="00971559559123"/>

  <add name="Service_Operator_Name" value="admin"/>
  <add name="Service_Operator_Password" value="admin"/>

  <add name="Service_Operator_Address_VTadp" value="https://hornet.org.com:1337/main/basicHttp"/>
  <add name="Service_Operator_Address_Admin" value="https://hornet.org.com:1337/Admn/basicHttp"/>
  <add name="Service_Operator_Address_PWR" value="https://hornet.org.com:1337/PWR/basicHttp"/>

</organizationConfig>
    [ConfigurationCollection(typeof(OrganizationConfig), AddItemName = "organizationConfig")]
    public class SpecificConfigurations : ConfigurationElementCollection
    {
        #region Indexer
        public OrganizationConfig this[int index]
        {
            get { return BaseGet(index) as OrganizationConfig; }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }

                BaseAdd(index, value);
            }
        }
        #endregion

        #region Public Method(s)
        public OrganizationConfig GetServiceInfo(string serviceName)
        {
            return BaseGet(serviceName) as OrganizationConfig;
        }
        #endregion

        #region Overridden Method(s)
        protected override ConfigurationElement CreateNewElement()
        {
            return new OrganizationConfig();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((OrganizationConfig)element).Name;
        }
        #endregion
    }

    public class OrganizationConfig : ConfigurationSection
    {
        #region Configuration Properties
        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get { return this["name"] as string; }
            set { this["name"] = value; }
        }

        [ConfigurationProperty("", IsDefaultCollection = true)]
        public NameValueConfigurationCollection Settings
        {
            get { return (NameValueConfigurationCollection)base[""]; }
        }
        #endregion
    }