How to use application settings with class libraries in winforms?

If I create app.config for my main application, I can use it using:

string test = Properties.Settings.Default.LibTest; 

Where on app.config you can find:

 <applicationSettings> <RManager.Properties.Settings> <setting name="LibTest" serializeAs="String"> <value>ola lib</value> </setting> </RManager.Properties.Settings> 

The question is, do I have a class library, is there a way to access the same settings using:

 string libString = Properties.Settings.Default.LibTest; 

If not, what is the best solution to access the settings from the main application?

+4
source share
2 answers

I would say that this is not correct if your libral can get the property from the main application. I suggest the following:

Create another static class (fe SettingsManager) in libral (or in some shared lib), and after the application has run the data from appconfig into this regular static class (SettingsManager). And this is a class property (SettingsManager) that you can use in your application and in your DLL.

If your dll and your application have many bindings, you should consider using the source from the dll in the exe application, in which case you can access the app.config settings.

+3
source

Essentially, you need to make the settings public and access them from another assembly.

Here are my answers to a couple of previous questions that are similar in nature:

0
source

Source: https://habr.com/ru/post/1336996/


All Articles