如何使Application.Properties.Settings公众和保持下去(How to M

2019-07-30 20:32发布

我在我的集​​中化应用程序设置到一个位置的过程中,我选择使用的设置集合在我的公共库这样做。

我提出这些设置到自己的文件,该文件被载入到我的app.config使用config来源:

<Common.Properties.Settings configSource="config\Common.Properties.Settings.config" />

这让我使用Visual Studio的“添加链接”功能,我的网站和测试应用程序中导入配置文件来覆盖默认库设置。

现在,我希望能够访问所有这些伟大的设置值,从我的其他库中,并且已经发现,我可以简单地通过使生成的类公共这么做:

文件:Common.Properties.Settings

public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase

这让我可以访问之类的东西Common.Properties.Settings.Default.MySetting从我的Web应用程序或单元测试中。 然而,问题是,每当添加新设置,Setting.settings文件由Visual Studio的再生,并翻转设置类回国内:

internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase

所以我的问题是,是否有人的方法来覆盖这一点,或许暗示宏观方法或一些其他方法,以确保Settings.settings文件重建之后,这个类设置为公开,知道了。

谢谢!

Answer 1:

我假设你已经创建和修改设置,形成编辑Visual Studio中建立一个可以通过项目属性部分设置进行访问。 在同一个编辑器还有就是你需要从内部改变公众被标记为访问修饰符的组合框。



文章来源: How to Make Application.Properties.Settings public and stay that way