Answer the question
In order to leave comments, you need to log in
What is the best way to work with an ini file?
I decided to collect the settings in one class.
It turns out something like that, only very long.
Is it possible to somehow simplify the work with the ini-file?
From conditions:
It is desirable to use an ini-file.
The configuration file must be in the same folder as the program.
public static class Explorer3d
{
private const string section = "3dExplorer";
private static bool? openexplorerpanel;
private static int? explorersplitterdistance;
// true
public static bool OpenExplorerPanel
{
get
{
if (openexplorerpanel.HasValue)
return openexplorerpanel.Value;
return IniSettings.GetIniSettingType<bool>(Settings.Paths.IniFile, section, "OpenExplorerPanel");
}
set
{
openexplorerpanel = value;
IniSettings.SetIniSetting(Settings.Paths.IniFile, section, "OpenExplorerPanel", value);
}
}
public static int ExplorerSplitterDistance
{
get
{
if (explorersplitterdistance.HasValue)
return explorersplitterdistance.Value;
return IniSettings.GetIniSettingType<int>(Settings.Paths.IniFile, section, "ExplorerSplitterDistance");
}
set
{
explorersplitterdistance = value;
IniSettings.SetIniSetting(Settings.Paths.IniFile, section, "ExplorerSplitterDistance", value);
}
}
...
Answer the question
In order to leave comments, you need to log in
I recommend to abandon INI files and use AppSettings to manage application configuration . If the configuration has a complex structure, then Custom Configuration Sections can be used .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question