我之前已经设计了一个自定义节处理程序,但我面对的是我似乎无法想出一个问题。 我有这样的配置部分:
<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>
我创建了以下处理类:
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;
}
}
}
}
我需要什么样的代码在这些类,才能成功执行下面的代码?
string query = ProvidersSection["tasks"].Queries["Insert"];