O
O
Oleksandr2014-06-23 16:50:18
C++ / C#
Oleksandr, 2014-06-23 16:50:18

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

1 answer(s)
A
Artem Voronov, 2014-06-23
@newross

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 question

Ask a Question

731 491 924 answers to any question