使用以下一组类:
public class MyConfigSection : ConfigurationSection
{
[ConfigurationProperty("Items")]
public ItemCollection Items
{
get { return ((ItemCollection)(base["Items"])); }
}
}
[ConfigurationCollection(typeof(ItemElement), AddItemName = "Item")]
public class ItemCollection : ConfigurationElementCollection
{
...
}
public class ItemElement : ConfigurationElement
{
...
}
我把配置部分的阅读整理成如下形式:
<MySection>
<Items>
<Item ... />
<Item ... />
<Item ... />
</Items>
</MySection>
如果我希望该部分看起来像,是否可以以某种方式设置阅读
<MySection>
<Item ... />
<Item ... />
<Item ... />
</MySection>
那些。这样集合的元素就不会被包含在 中<Items></Items>,而是直接从节中读取。
尝试使用一个参数
IsDefaultCollection和一个空字符串作为键: