Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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# 带有键和属性的自定义配置节_C#_Configuration_Web Config - Fatal编程技术网

C# 带有键和属性的自定义配置节

C# 带有键和属性的自定义配置节,c#,configuration,web-config,C#,Configuration,Web Config,我需要创建一个类似appsettings的配置部分,但在周围的元素上有一个属性,例如: <userSettings> <machine name="my-machine"> <setting key="Site" value="http://localhost" /> <setting key="Online" value="true" /> </machine> <!--

我需要创建一个类似appsettings的配置部分,但在周围的元素上有一个属性,例如:

<userSettings>
    <machine name="my-machine">
        <setting key="Site" value="http://localhost" />
        <setting key="Online" value="true" />
    </machine>
    <!-- more machines -->
</userSettings>
和背景

public class SettingElement : ConfigurationElement
{
    [ConfigurationProperty("key", IsRequired = true, IsKey = true)]
    public string Key
    {
        get { return this["key"].ToString(); }
    }

    [ConfigurationProperty("value", IsRequired = true)]
    public string Value
    {
        get { return this["value"].ToString(); }
    }
}

为什么不创建一个新的xml文件,而不是使用配置文件呢。如果您使用xml文件,管理和操作将非常容易,但实际上没有帮助……为什么不创建一个新的xml文件,而不是使用配置文件呢。如果您使用xml文件,它将非常容易管理和操作,这对您毫无帮助。。。
public class SettingElement : ConfigurationElement
{
    [ConfigurationProperty("key", IsRequired = true, IsKey = true)]
    public string Key
    {
        get { return this["key"].ToString(); }
    }

    [ConfigurationProperty("value", IsRequired = true)]
    public string Value
    {
        get { return this["value"].ToString(); }
    }
}