0

I want to set up following behaviour :

My Application uses a config file, created through the ConfigDesigner. Therefor I created a Default-Configuration

namespace MyApp.Configuration {


[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
public sealed partial class MyConfig: global::System.Configuration.ApplicationSettingsBase {


    [global::System.Configuration.UserScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("100")]
    public double Size{
        get {
            return ((double)(this["Size"]));
        }
        set {
            this["Size"] = value;
        }
    }
  }
 }

Through a call via MyConfig.Default.Size, I get the Value, which is stored on MyApp.exe.config.

But now I want to decide on runtime (it's possible that these Bool can change multiple times), if the user is allowed to use the MyApp.exe.config. So I changed the setter of my MyConfig.Default-Property to:

private static MyConfig userInstance = ((MyConfig)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new MyConfig())));
public static MyConfig Default
    {
        get
        {
            if(ConfigIsAllowed)
                return userInstance;
            else
            {
                /* Here I wanna return the default-values */
            }
        }
    }

But I have no idea, how to return the default configuration. I know, that there is a possibility to Reset() the config, but I don't want to reset the File, where config is stored. I only want to return default values. I also found a solution to return one default value via MyConfig.Default.Properties["NAME"].DefaultValue, but by using this, I can't use a configvalue like MyConfig.Default.Size.

What is the best soltuion to get a default config or the user config?

Kooki
  • 1,157
  • 9
  • 30

0 Answers0