问题描述
我正在将我的应用程式设定集中到一个位置,我已选择使用我的公用程式库中的「设定」集合。
I am in the process of centralizing my application settings into one location and I've chosen to use the the Settings collection in my common library to do so.
我已经将所有这些设置移动到自己的文件,它被拉入我的app.config使用config source:
I have moved all these settings into their own file that gets pulled into my app.config using config source:
<Common.Properties.Settings configSource="config\Common.Properties.Settings.config" />
这允许我使用Visual Studio的添加链接功能来覆盖默认库设置在我的web和测试应用程序中导入的配置文件。
This allows me to use the "Add Link" capability of Visual Studio to override the default library settings with the imported config file within my web and test applications.
现在,我想能够从其他库中访问所有这些伟大的设置值,我可以简单地通过将生成的类公开:
Now, I want to be able to access all of these great Settings values from within my other libraries, and have found that I can do so simply by making the generated class public:
File:Common.Properties.Settings
File: Common.Properties.Settings
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
这让我可以从我的Web应用程序或单元测试中访问 Common.Properties.Settings.Default.MySetting
。然而,问题是,每当添加一个新的设置,Setting.settings文件由Visual Studio重新生成,并将设置类返回内部:
This lets me get access to things like Common.Properties.Settings.Default.MySetting
from within my web application or unit tests. However, the problem is that whenever a new setting is added, the Setting.settings file is regenerated by Visual Studio, and flips the Settings class back to internal:
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
所以我的问题是,是否有人知道一种方法来覆盖这个,或者可能建议一个宏方法或一些其他方法,以确保在Settings.settings文件重建后,此类设置为public。
So my question is whether anyone knows of a way to override this, or perhaps suggest a macro approach or some other method to ensure that after the Settings.settings file is rebuilt, this class is set to public.
谢谢!
推荐答案
我假设你已经在编辑器中创建和修改了visual studio build可以通过项目属性部分设置访问。在同一个编辑器上有一个组合框,您需要从内部更改为公开,它被标记为访问修饰符。
I assume that you have created and modified settings form visual studio build in editor that can be accessed through project properties section settings. On the same editor there is an combobox that you need to change from internal to public it is marked as Access Modifier.
这篇关于如何使Application.Properties.Settings public和保持那种方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!