在web.config中为具有随机数量的元素的web.config创建一个自定义块 [英] Create a custom block in web.config for web.config with a random number of elements
问题描述
我需要在Web配置中创建一个自定义块,如下所示:
I need to create a custom block in web config as follows:
<MySettings>
<add name="name1" value="value1" />
<add name="name2" value="value2" />
<add name="name3" value="value3" />
...
</MySettings>
我了解,我应该从ConfigurationSection派生我的自定义设置类,但我不知道如何使其可扩展.我需要在该块中添加很多项目,并将其用作键值对.
Ad i understand, i should derive my custom settings class from ConfigurationSection, but i don't know how to make it scalable. I need to add a lot of items to that block, and use it as a key-value pair.
我也理解可以通过部分完成所有操作,但是我需要创建一个自定义字段,因为键和值字段对我来说可能不够用,我需要对其进行扩展.
I also understand that it's possible to do it all through section, but i need to create a custom one, since key and value fields might not be enough for me and i will need to extend them.
非常感谢您的帮助!
推荐答案
要创建添加/清除/删除子元素的结构,与 MySettings
元素匹配的类型需要从 ConfigurationElementCollection .
To create a structure of add/clear/remove child elements the type matching the MySettings
element needs to derive from ConfigurationElementCollection.
这篇关于在web.config中为具有随机数量的元素的web.config创建一个自定义块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!