简体   繁体   中英

C# access different Settings

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM