相关疑难解决方法(0)

如何使用ConfigurationElementCollection实现ConfigurationSection

我正在尝试在项目中实现自定义配置部分,并且我一直在遇到我不理解的异常.我希望有人能填补这里的空白.

App.config看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="ServicesSection" type="RT.Core.Config.ServicesConfigurationSectionHandler, RT.Core"/>
    </configSections>
    <ServicesSection type="RT.Core.Config.ServicesSection, RT.Core">
            <Services>
                <AddService Port="6996" ReportType="File" />
                <AddService Port="7001" ReportType="Other" />
            </Services>
        </ServicesSection>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我有一个ServiceConfig像这样定义的元素:

public class ServiceConfig : ConfigurationElement
  {
    public ServiceConfig() {}

    public ServiceConfig(int port, string reportType)
    {
      Port = port;
      ReportType = reportType;
    }

    [ConfigurationProperty("Port", DefaultValue = 0, IsRequired = true, IsKey = true)]
    public int Port 
    {
      get { return (int) this["Port"]; }
      set { this["Port"] = value; …
Run Code Online (Sandbox Code Playgroud)

c# configuration app-config configuration-files

157
推荐指数
5
解决办法
14万
查看次数