I have designed a custom section handler before but I'm faced with a problem that I can not seem to think up. I have a configuration section like this:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="providers" requirePermission="false" type="MyProject.Configuration.ProvidersSection"/>
</configSections>
<providers>
<provider name="products">
<queries>
<add name="insert" value="InsertProduct" />
<add name="retrieve" value="GetProduct" />
<add name="collect" value="GetProducts" />
<add name="update" value="UpdateProduct" />
<add name="delete" value="DeleteProduct" />
<queries>
</provider>
<provider name="tasks">
<queries>
<add name="insert" value="InsertTask" />
<add name="retrieve" value="GetTaskById" />
<add name="collect" value="GetMultipleTasks" />
<add name="update" value="UpdateTask" />
<add name="delete" value="DeleteTask" />
<queries>
</provider>
<provider name="events">
<queries>
<add name="insert" value="AddEvent" />
<add name="retrieve" value="GetEvent" />
<add name="collect" value="GetEvents" />
<add name="update" value="UpdateEvent" />
<add name="delete" value="DeleteEvent" />
<queries>
</provider>
</providers>
</configuration>
I created the following handler classes:
using System.Configuration;
namespace MyProject.Configuration
{
public class ProvidersSection : ConfigurationSection
{
public new Element this[string key]
{
get
{
}
}
}
[ConfigurationCollection(typeof(ProviderElement))]
public class ProvidersCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new ProviderElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return element.ElementInformation.Properties["name"].Value;
}
public ProviderElement this[string key]
{
get
{
return (ProviderElement)base.BaseGet(key);
}
}
}
public class ProviderElement : ConfigurationElement
{
public string this[string name]
{
get
{
return string.Empty;
}
}
}
}
What code do I need in these classes in order to successfully execute the following code?
string query = ProvidersSection["tasks"].Queries["Insert"];