我正在尝试构建自定义配置,但由于某种原因,我无法让它工作。如果有人能看到我的问题出在哪里,我将不胜感激。
这是代码:
public class PointServices : ConfigurationSection
{
public static PointServices Get()
{
var t = ConfigurationManager.GetSection("point.Services/xServices") as PointServices;
return t;
}
//<summary>
//Declares a collection element represented in the following configuration sub-section
//<singleInstances> <add .../> </singleInstances>
//</summary>
[ConfigurationProperty("xServices", IsDefaultCollection = true)]
[ConfigurationCollection(typeof(PointServices))]
public PointServicesCollection Services
{
get
{
//var v = base["xServices"];
return (PointServicesCollection) base["xServices"];
}
}
}
public class PointService : ConfigurationElement
{
[ConfigurationProperty("name",IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
}
[ConfigurationProperty("type", IsRequired = true)]
public string Type
{
get
{
return this["type"].ToString();
}
}
}
这是配置:
<sectionGroup name="point.Services">
<section name="xServices" type="XYZ.Messaging.PointServiceConfiguration.PointServices, XYZ.Point.Messaging" />
</sectionGroup>
...
<point.Services>
<xServices>
<xService>
<add name="XYZService" type="XYZService" />
</xService>
</xServices>
</point.Services>
当我运行:PointServices.Get()
时,我得到:
无法识别的元素“xService”。
我尝试将 xService 添加到部分定义中,如下所示:
<section name="xService" type="XYZPoint.Messaging.PointServiceConfiguration.PointService, Barcap.FIA.Point.Messaging" />
但它似乎没有帮助。
如果有人有任何想法,请帮助!谢谢