Home > other >  C# access different Settings
C# access different Settings

Time:04-13

In my app, I have added 3 different *.settings files. Upon a selection, I want to use different App settings, so I need to change the default.

Normally we access it via

Settings.Default

How can I set different ones? I already have created the files

CodePudding user response:

It depends to where you have added setting files. For example, assuming you have added Settings1.setting in Properties folder, then you can access it in code through Properties.Settings1.Default.

The .settings files use a custom tool (SettingsSingleFileGenerator) which follows Visual Studio's standards to generate namespace for the file. To use a different namespace for the generated code, you can put the file in a custom folder hierarchy which will be used as namespace of the class, or you can easily set the Custom Tool Namespace of the .settings file.

You can open the underlying .Designer.cs of your .settings file and and you see the namespace, class name, and the Default property which returns a single instance of your Settings1 class (singleton).

  • Related