【发布时间】:2016-02-02 18:07:34
【问题描述】:
在一个winform C#项目中,我在项目设置中添加了HomeDir作为目录路径。我想将其初始值设置为Documents 文件夹。这个目录不是一个常量字符串,所以我不能在设置对话框和Settings.Designer.cs中使用它,比如:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments))]
public string HomeDir
{
get
{
return ((string)(this["HomeDir"]));
}
set
{
this["HomeDir"] = value;
}
}
会报如下错误:
错误1 属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式
【问题讨论】:
标签: c# winforms settings default