Configurations and Settings for C #

I am starting to develop a configuration and settings component for the application. I need an easy way to read dictionary style settings, as well as a way to store simple arrays at a persistence level.

Does a component already in use exist? (something like log4net for logging) what options should I look at?

+3
source share
7 answers

Take a look at App.Config and the ConfigurationManager class .

+4
source

You really don't need to do this: .NET BCL already has everything you need.

+5
source

"" SolutionExplorer, Settings.Settings. . , . , , .

:

Drink TextBox drinkTextBox. :

drinkTextBox.Text = Properties.Settings.Default.Drink;

:

Properties.Settings.Default.Drink = drinkTextBox.Text;
Properties.Settings.Default.Save();
+4

, , ( " " > "" ), .

. , Save, Load Reload

+3

, , System.Configuration.ConfigurationManager. , app/web.config, .

, ,

public static string NorthwindConnectionString
{
  get{return ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString
}

, , confiuration intellisense . , .

, . , , ( , , , ini ..).

+2

appSettings. . CodeProject .

/ , , - .

0

, .

System.Collections.Specialized.StringDictionary, , , System.Collections.Specialized.StringCollection( ). Keys, - . , , StringCollections StringDictionary . , .

public static StringDictionary NamedValues = new StringDictionary();
public static ClassName() // static construtor
{
  StringCollection keys = Properties.Settings.Default.Keys;
  StringCollection vals = Properties.Settings.Default.Values;
  for(int i = 0; i < keys.Count(); i++)
  {
     NamedValues.Add(keys[i], vals[i]);
  }
}
0

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


All Articles