我有一个从配置文件中读取的配置部分。xml 看起来像这样
<GroupBySection>
<Groups>
<Group name="Source" product="Product One">
<Items>
<Item name="2003" type="radio" />
<Item name="2007" type="radio" />
<Item name="2010" type="radio" />
<Item name="2013" type="radio" />
<Item name="o365" type="radio" />
</Items>
</Group>
<Group name="Target" product="Product One">
<Items>
<Item name="2003" type="radio" />
<Item name="2007" type="radio" />
<Item name="2010" type="radio" />
<Item name="2013" type="radio" />
<Item name="o365" type="radio" />
</Items>
</Group>
<Group name="Source" product="Product Two">
<Items>
<Item name="2003" type="radio" />
<Item name="2007" type="radio" />
<Item name="2010" type="radio" />
<Item name="2013" type="radio" />
<Item name="o365" type="radio" />
</Items>
</Group>
</Groups>
</GroupBySection>
当我调用此配置部分并进行计数时,我只看到第一个 Product One 结果。产品二不显示,这是因为名称也是“来源”。我希望它显示所有它们,无论名称是否相同。所以简而言之,即使我想要它,它也不会返回它已经遇到的同名的任何东西。谁能指出我做错了什么?
下面的代码
配置部分
public class GroupByConfiguration : ConfigurationSection
{
[ConfigurationProperty("Groups")]
public GroupByElementCollection Groups
{
get { return ((GroupByElementCollection)(base["Groups"])); }
set { base["Groups"] = value; }
}
}
元素部分
public class GroupByElement : ConfigurationElement
{
// Group Attributes
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get { return (string)base["name"]; }
}
[ConfigurationProperty("product", IsRequired = true)]
public string Product
{
get { return (string)base["product"]; }
}
[ConfigurationProperty("Items")]
public ItemElementCollection Items
{
get { return ((ItemElementCollection)(base["Items"])); }
set { base["Items"] = value; }
}
}
元素集合
[ConfigurationCollection(typeof(GroupByElement))]
public class GroupByElementCollection : ConfigurationElementCollection
{
internal const string PropertyName = "Group";
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMapAlternate;
}
}
protected override string ElementName
{
get
{
return PropertyName;
}
}
protected override bool IsElementName(string elementName)
{
return elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
}
public override bool IsReadOnly()
{
return false;
}
protected override ConfigurationElement CreateNewElement()
{
return new GroupByElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((GroupByElement)(element)).Name;
}
public GroupByElement this[int idx]
{
get { return (GroupByElement)BaseGet(idx); }
}
}
我相信这是愚蠢的:)提前谢谢!