I am trying to have the following section structure in my app.config
<MyConfig>
<NewsFeeds site="abc">
<add name="first" />
</NewsFeeds>
<NewsFeeds site="zyx">
<add name="another" />
</NewsFeeds>
</MyConfig>
I already have the MyConfig
section working but I am unsure of how the NewsFeed
collection should be coded, or if this structure is even possible. Right now I have the following classes so far:
[ConfigurationCollection(typeof(NewsFeedConfig))]
public class NewsFeedConfigCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new NewsFeedConfig();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((NewsFeedConfig)(element)).Name;
}
public NewsFeedConfig this[int idx] { get { return (NewsFeedConfig)BaseGet(idx); } }
}
public class NewsFeedConfig : ConfigurationElement
{
[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
public string Name
{
get { return (string)base["name"]; }
set { base["name"] = value; }
}
[ConfigurationProperty("source", IsRequired = true)]
public string Source
{
get { return (string)base["source"]; }
set { base["source"] = value; }
}
}
However, this requires that all news feeds be under one news feed collection, and then i'd have to parse them out manually by adding a Site
property to each element. That's fine, but is it possible to do it in a way that the XML defined above would work?