.net 如何使用ConfigurationElementCollection自定义ConfigurationSection

.net 如何使用ConfigurationElementCollection自定义ConfigurationSection,.net,collections,configuration,element,.net,Collections,Configuration,Element,如何使用.net中的ConfigurationElementCollection自定义ConfigurationSection 我的网络配置如下: <cachingConfig enable="true"> <cachingEngine name="Engine1" enable="true"> <instance name="Instance1" value="127.0.0.1:11211|127.0.0.2:11211|127.0.0.3:

如何使用.net中的ConfigurationElementCollection自定义ConfigurationSection

我的网络配置如下:

<cachingConfig enable="true">
    <cachingEngine name="Engine1" enable="true">
      <instance name="Instance1" value="127.0.0.1:11211|127.0.0.2:11211|127.0.0.3:11211" />
      <instance name="Instance2" value="127.0.0.1:11211" />
      <instance name="Instance3" value="127.0.0.1:11211" />
    </cachingEngine>
    <cachingEngine name="Engine2" enable="false">
      <instance name="Instance1" value="127.0.0.1:11211" />
      <instance name="Instance2" value="127.0.0.1:11211" />
    </cachingEngine>    
  </cachingConfig>
}

[ConfigurationCollectionTypeofChineseEngine,CollectionType=ConfigurationElementCollectionType.BasicMapAlternate] 公共类ItemCollection1:ConfigurationElementCollection { 内部常量字符串ItemPropertyName=cachingEngine

public override ConfigurationElementCollectionType CollectionType
{
    get { return ConfigurationElementCollectionType.BasicMapAlternate; }
}

protected override string ElementName
{
    get { return ItemPropertyName; }
}

protected override bool IsElementName(string elementName)
{
    return (elementName == ItemPropertyName);
}

protected override object GetElementKey(ConfigurationElement element)
{
    return ((CachingEngine)element).Name;
}

protected override ConfigurationElement CreateNewElement()
{
    return new CachingEngine();
}

public override bool IsReadOnly()
{
    return false;
}
}

[ConfigurationCollectiontypeofInstance,CollectionType=ConfigurationElementCollectionType.BasicMapAlternate,AddItemName=instance] 公共类ItemCollection2:ConfigurationElementCollection { 内部常量字符串ItemPropertyName=实例

public override ConfigurationElementCollectionType CollectionType
{
    get { return ConfigurationElementCollectionType.BasicMapAlternate; }
}

protected override string ElementName
{
    get { return ItemPropertyName; }
}

protected override bool IsElementName(string elementName)
{
    return (elementName == ItemPropertyName);
}

protected override object GetElementKey(ConfigurationElement element)
{
    return ((CachingEngine)element).Name;
}

protected override ConfigurationElement CreateNewElement()
{
    return new CachingEngine();
}

public override bool IsReadOnly()
{
    return false;
}
}

公共类CachingEngine:ConfigurationElement { [ConfigurationPropertyname,DefaultValue=,IsRequired=true] 内部字符串名 { 获取{return stringthis[name];} 设置{this[name]=value;} }

}

公共类实例:ConfigurationElement { [ConfigurationPropertyname,DefaultValue=,IsRequired=true] 内部字符串名 { 获取{return stringthis[name];} 设置{this[name]=value;} }


}

你能详细说明你想做什么吗?问题不是很清楚。请不要只是贴一堵代码墙,然后让别人来修复它。隔离你的问题并问一个具体的问题。
public override ConfigurationElementCollectionType CollectionType
{
    get { return ConfigurationElementCollectionType.BasicMapAlternate; }
}

protected override string ElementName
{
    get { return ItemPropertyName; }
}

protected override bool IsElementName(string elementName)
{
    return (elementName == ItemPropertyName);
}

protected override object GetElementKey(ConfigurationElement element)
{
    return ((CachingEngine)element).Name;
}

protected override ConfigurationElement CreateNewElement()
{
    return new CachingEngine();
}

public override bool IsReadOnly()
{
    return false;
}
[ConfigurationProperty("enable", DefaultValue = true, IsRequired = true)]
internal bool Enable
{
    get { return (bool)this["enable"]; }
    set { base["enable"] = value; }
}

public ItemCollection2 Instance
{
    get { return ((ItemCollection2)(base["instance"])); }
    set { base["instance"] = value; }
}
[ConfigurationProperty("value", DefaultValue = "", IsRequired = true)]
internal string Value
{
    get { return (string)this["value"]; }
    set { base["value"] = value; }
}