我应该在 app.config 的 applicationSettings 部分输入什么内容(在这两种情况下),以便在阅读设置时,我可以获得以下信息:
?
我想没有办法实现这两种情况,还是我错过了什么?
不幸的是,需要区分字符串值是空值还是空值,因为这个值进入不同的系统,对这两个系统做出不同的决定。
谢谢
更多信息:
每次修改设置选项卡时都会重新生成 Settings.Designer.cs。
示例生成的设置是:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Foo {
get {
return ((string)(this["Foo "]));
}
set {
this["Foo "] = value;
}
}
问题在于生成的 [DefaultSettingValueAttribute("")]。当我使用 [DefaultSettingValueAttribute(null)] 手动更正它时,它可以正常工作,但是,每当我修改设置选项卡上的任何内容时,我都需要这样做,这是 Not Acceptable 。
任何线索?
最佳答案
你是对的,没有办法同时实现这两种情况,因为 null != String.Empty
.
但是你可以使用 Boolean String.IsNullOrEmpty(String)
检查这两种情况。
关于.NET 应用程序设置 -> 设置空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3175881/