[英]Change the default value of a settingsvalue
id didnt find anything on Stackoverflow or on the internet, im sorry if this question was already posted (or if its simply impossible). id没有在Stackoverflow或互联网上找到任何东西,对不起,如果这个问题已经发布(或者如果它根本不可能)。
Is there a way to change the default value of a *.settigs-property, for example if i have the setting "USER" 有没有办法更改* .settigs属性的默认值,例如,如果我有设置“USER”
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("TESTUSER")]
public string SQLServer {
get {
return ((string)(this["USER"]));
}
set {
this["USER"] = value;
}
}
would there be a way to change (at runtime) the DefaultSettingValueAttribute ("TESTUSER") to another value (ie: "John Doe"). 是否有办法将DefaultSettingValueAttribute(“TESTUSER”)(在运行时)更改为另一个值(即:“John Doe”)。
Thanks in advance 提前致谢
You can override the Properties
property of the ApplicationSettingsBase
class: 您可以覆盖ApplicationSettingsBase
类的Properties
属性:
public override SettingsPropertyCollection Properties
{
get
{
var properties = base.Properties;
properties["SQLServer"].DefaultValue =
String.Format("John Doe {0}", DateTime.Now);
return properties;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.