How to Make Application.Properties.Settings public and stay that way

房东的猫 提交于 2020-01-13 07:45:07

问题


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.

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" />

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

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

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

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.

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/11873656/how-to-make-application-properties-settings-public-and-stay-that-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!