0

我正在尝试构建自定义配置,但由于某种原因,我无法让它工作。如果有人能看到我的问题出在哪里,我将不胜感激。

这是代码:

    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" />但它似乎没有帮助。

如果有人有任何想法,请帮助!谢谢

4

2 回答 2

1

你需要另一个用于 xService 的说明符

<sectionGroup name="point.Services">          
  <sectionGroup name="xServices">          
    <section name="xService" 
      type="XYZ.Messaging.PointServiceConfiguration.PointServices, XYZ.Point.Messaging" />  
  </sectionGroup name="xServices">         
</sectionGroup>
于 2009-11-19T22:51:37.833 回答
0

xServices 应该是一个sectionGroup,而不是一个section。并且 xService 应该被定义为一个部分。

于 2009-11-19T22:47:24.787 回答