应用程序设置保存
我的应用程序中有两个程序集。 MyApplication.BO
和 MyApplication.GUI
。
我已经为我的 BO 程序集配置了属性设置。
现在,当我尝试编译以下代码时:
public class MyApplicationInfo
{
private string _nameOfTheUser;
public string FullNameOfTheUser
{
get { return _nameOfTheUser; }
set { _nameOfTheUser = value; }
}
public void Save()
{
try
{
MyApplication.BO.Properties.Settings.Default.FullNameOfTheUser = this.FullNameOfTheUser;
MyApplication.BO.Properties.Settings.Default.Save();
}
catch (Exception ex)
{
throw ex;
}
}
}
VS2005 给出以下编译错误:
错误 1 属性或索引器“MyApplication.BO.Properties.Settings.FullNameOfTheUser”无法分配给 - 它是只读的 F:\CS\MyApplication\MyApplication.BO\MyApplicationInfo.cs 57 17 MyApplication.BO
我的有什么问题方法?
I have two assemblies in my application. MyApplication.BO
and MyApplication.GUI
.
I have configured property-settings for my BO assembly.
Now when I am trying to compile the following code:
public class MyApplicationInfo
{
private string _nameOfTheUser;
public string FullNameOfTheUser
{
get { return _nameOfTheUser; }
set { _nameOfTheUser = value; }
}
public void Save()
{
try
{
MyApplication.BO.Properties.Settings.Default.FullNameOfTheUser = this.FullNameOfTheUser;
MyApplication.BO.Properties.Settings.Default.Save();
}
catch (Exception ex)
{
throw ex;
}
}
}
VS2005 is giving me the following compilation error:
Error 1 Property or indexer 'MyApplication.BO.Properties.Settings.FullNameOfTheUser' cannot be assigned to -- it is read only F:\CS\MyApplication\MyApplication.BO\MyApplicationInfo.cs 57 17 MyApplication.BO
What is wrong with my approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在设置设计器中,确保 FullNameOfTheUser 的 Scope 属性设置为“User”。如果您创建应用程序范围的设置,它将生成为只读属性。有关详细信息,请参阅本文。
In the Settings designer, make sure that the Scope property for FullNameOfTheUser is set to "User". If you create an Application-scoped setting, it is generated as a read-only property. Take a look at this article for more information.
该设置需要有用户,而不是应用程序范围。
The setting needs to have user, not application scope.