如何为另一个应用程序的 *.config 文件中的 AppSettings 部分实现包装类?
我在项目中的应用程序很少。每个应用程序都有自己的 *.config 文件。
我需要编写配置应用程序,以使用舒适的 GUI(仅每个文件的 appConfig 部分)同时配置所有这些应用程序的 *.config 文件。
因此,我需要以某种方式为每个 *.config 文件 appSettings 部分创建包装器(将其与 WPF DataBinding 一起使用)。但我不知道怎么做。
我尝试基于 AppSettingsBase 或 ConfigurationSection 创建包装类(AppSettingsSection 类已密封),如果我尝试使用应用程序自己的配置文件,它会起作用。 但是,在使用外部配置时,您可以访问 AppSettingsSection 对象,而不是 NameValueCollection。而且我无法将 NameValueCollection 转换为 AppSettingsSection,因此我无法使用包装类来使用它。
public sealed class Client_exe_AppConfigSectionHandler : ApplicationSettingsBase
{
public Client_exe_AppConfigSectionHandler()
{
}
[ConfigurationProperty( "ValidBrushColor",
DefaultValue = "107814",
IsRequired = true,
IsKey = true )]
public string validBrushColor
{
get
{
return ( string )this[ "ValidBrushColor" ];
}
set
{
this[ "ValidBrushColor" ] = value;
}
}
}
需要包装器类,因为我需要 WPF 数据绑定。
I have few applications in a project. Each app has its own *.config file.
I need to write configuration app to configure all these apps' *.config files simultaneously with comfortable GUI (only appConfig section of each file).
So I need somehow create wrappers (to use it with WPF DataBinding) for every *.config file appSettings section. But I can't figure out how.
I tried to create wrapper class based on AppSettingsBase or ConfigurationSection (AppSettingsSection class is sealed) and it would work if I was trying to work with application's own config file.
But when working with external config, you're having access to AppSettingsSection object, instead of NameValueCollection. And I can't cast NameValueCollection to AppSettingsSection, so I can't work with it using wrapper class.
public sealed class Client_exe_AppConfigSectionHandler : ApplicationSettingsBase
{
public Client_exe_AppConfigSectionHandler()
{
}
[ConfigurationProperty( "ValidBrushColor",
DefaultValue = "107814",
IsRequired = true,
IsKey = true )]
public string validBrushColor
{
get
{
return ( string )this[ "ValidBrushColor" ];
}
set
{
this[ "ValidBrushColor" ] = value;
}
}
}
Wrapper class is needed because I need WPF Data Binding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论