Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 Web.config嵌套列表_C# 4.0 - Fatal编程技术网

C# 4.0 Web.config嵌套列表

C# 4.0 Web.config嵌套列表,c#-4.0,C# 4.0,我想在我的web.config中使用嵌套列表。我看到了一些可以工作的代码,但不是我的,当我试图阅读配置部分时出现了一个错误: System.Configuration.ConfigurationErrorsException:未安装 重新连接等时服务系统' 我的配置: <IsochroneServicesTest> <add name="TC"> <IsochroneServicesTestImbrique> <add

我想在我的web.config中使用嵌套列表。我看到了一些可以工作的代码,但不是我的,当我试图阅读配置部分时出现了一个错误:

System.Configuration.ConfigurationErrorsException:未安装 重新连接等时服务系统'

我的配置:

<IsochroneServicesTest>
    <add name="TC">
      <IsochroneServicesTestImbrique>
        <add name="DEFAULT" path="success"/>
      </IsochroneServicesTestImbrique>
    </add>
  </IsochroneServicesTest>

感谢您的帮助

您收到了该错误,因为您在
部分中缺少了
isochroneseservicestistimbrique
的声明。此外,至少必须有一个类继承自
ConfigurationSection
。参见示例

    [ConfigurationProperty("IsochroneServicesTest")]
    [ConfigurationCollection(typeof(CollectionIsochrone), AddItemName = "add")]
    public CollectionIsochroneType IsochroneServicesTest
    {
        get { return (CollectionIsochroneType)this["IsochroneServicesTest"]; }
        set { this["IsochroneServicesTest"] = value; }
    }

    public class CollectionIsochroneType : ConfigurationElementCollection
    {
        public void Add(ProviderElement element)
        {
            base.BaseAdd(element);
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new IsochroneElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((IsochroneTypeElement)element).Name;
        }

        public IsochroneTypeElement this[int index]
        {
            get { return (IsochroneTypeElement)BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        public new IsochroneTypeElement this[string Name]
        {
            get { return (IsochroneTypeElement)BaseGet(Name); }
        }

        public int IndexOf(IsochroneTypeElement element)
        {
            return BaseIndexOf(element);
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }
    }

    public class IsochroneTypeElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }

        [ConfigurationProperty("IsochroneServicesTestImbrique", IsRequired = true)]
        [ConfigurationCollection(typeof(CollectionIsochrone), AddItemName = "add")]
        public CollectionIsochrone IsochroneServicesImbrique
        {
            get { return (CollectionIsochrone)this["IsochroneServicesTestImbrique"]; }
            set { this["IsochroneServicesTestImbrique"] = value; }
        }
    }

public class CollectionIsochrone : ConfigurationElementCollection
{
    public void Add(ProviderElement element)
    {
        base.BaseAdd(element);
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new IsochroneElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((IsochroneElement)element).Name;
    }

    public IsochroneElement this[int index]
    {
        get { return (IsochroneElement)BaseGet(index); }
        set
        {
            if (BaseGet(index) != null)
            {
                BaseRemoveAt(index);
            }
            BaseAdd(index, value);
        }
    }

    public new IsochroneElement this[string Name]
    {
        get { return (IsochroneElement)BaseGet(Name); }
    }

    public int IndexOf(IsochroneElement element)
    {
        return BaseIndexOf(element);
    }

    protected override void BaseAdd(ConfigurationElement element)
    {
        BaseAdd(element, false);
    }
}

public class IsochroneElement : ConfigurationElement
{
    [ConfigurationProperty("name", IsRequired = true)]
    public string Name
    {
        get { return (string)this["name"]; }
        set { this["name"] = value; }
    }

    [ConfigurationProperty("path", IsRequired = true)]
    public string Path
    {
        get { return (string)this["path"]; }
        set { this["path"] = value; }
    }
}