单不写设置默认值 [英] Mono doesn't write settings defaults

查看:144
本文介绍了单不写设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的问题。如果我只用一个Windows窗体项目,并呼吁只有 - Settings.Default.Save()运行时,它,单声道创建了每项设置的默认值的user.config文件。它是好的,到目前为止,一切顺利。

Here is my problem. If I use only one Windows Forms project and call only - Settings.Default.Save() when running it, Mono creates a user.config file with the default value for each setting. It is fine, so far so good.

但现在我想补充一个类库项目,该项目从Windows窗体引用的项目,我谨设置从Windows窗体项目的类库之一。现在我做同样的 - Settings.Default.Save()和我很大的惊喜,单声道创建为每个空值(而不是默认的)一个user.config文件设置?!什么是在Windows窗体项目或在类库一种具有设置之间的区别?顺便提一下它不是一个操作系统的问题。这是一个单声道的问题,因为它不会在Windows和Linux下运行。如果我不使用单声道一切都很好,但我必须端口我的应用程序到Linux,所以我不得不使用单声道。我真的很沮丧,它阻止一个项目:(

But now I add a class library project, which is referenced from the Windows Forms project and I move the settings from the Windows Forms project to the Class Library one. Now I do the same - Settings.Default.Save() and to my great surprise, Mono creates a user.config file with EMPTY values(NOT the default ones) for each setting?! What's the difference between having the settings in the Windows Forms Project or in the class library one? And by the way it is not a operating system issue. It is a Mono issue, because it doesn't work both under Windows and Linux. If I don't use Mono everything is fine, but I have to port my application to Linux, so I have to use Mono. I am really frustrated, it is blocking a project:(

编辑:如果我写 Settings.Default.Font = Settings.Default.Font; 调用 Settings.Default.Save(),那么它是否工作正常。这是什么?!

If I write Settings.Default.Font = Settings.Default.Font; before calling the Settings.Default.Save(), then it is working properly. What is this?!

在此先感谢您有任何建议。

Thanks in advance for any suggestion you have.

问候,
佩塔尔

Regards, Petar

推荐答案

确定,万一别人进入这个可怕的问题,我设法这样变通办法:

OK, in case someone else enters into this dreadful issue, I managed to workaround it this way:

Settings.Default.MySetting1 = Settings.Default.MySetting1;
Settings.Default.MySetting2 = Settings.Default.MySetting2;
.........................................................
Settings.Default.MySettingN = Settings.Default.MySettingN;

在我的应用程序是我开始执行该代码

I execute this code when my application is starting.

这篇关于单不写设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆