C# 中的递归自定义配置
我正在尝试创建一个遵循以下递归结构的自定义配置部分:
<monitorSettings>
<monitor description="description1" />
<monitor description="description2" />
<monitor description="description3">
<monitor description="description3.1" />
<monitor description="description3.2" />
</monitor>
</monitorSettings>
这可能吗?我不确定如何布置配置类。
我对监视器有以下内容:
public class Monitor : ConfigurationElement
{
[ConfigurationProperty("description", IsRequired = true)]
public String Description
{
get
{
return (String)this["description"];
}
set
{
this["description"] = value;
}
}
}
我需要添加什么才能使其递归?
I am trying to create a custom configuration section that follows the following recursive structure:
<monitorSettings>
<monitor description="description1" />
<monitor description="description2" />
<monitor description="description3">
<monitor description="description3.1" />
<monitor description="description3.2" />
</monitor>
</monitorSettings>
Is this possible? I am not sure how I would lay out the configuration classes.
I have the following for the monitor:
public class Monitor : ConfigurationElement
{
[ConfigurationProperty("description", IsRequired = true)]
public String Description
{
get
{
return (String)this["description"];
}
set
{
this["description"] = value;
}
}
}
What would I need to add to make it recursive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用如下所示的配置文件(对上面的稍作更改)
和如下配置类来执行此操作:
然后在 Windows 控制台应用程序中使用,例如:
You can do this with a config file like the following (slight change to the one above):
and configuration classes like:
Then to use in a Windows Console app for instance:
尝试配置组
ConfigurationSectionGroup 类
try configuration group
ConfigurationSectionGroup Class