I am using CommandLine Parser Library to parse command line arguments within an application.
There are some options that will in most cases be the same every time a user runs the application. Usually, I use the DefaultValue attribute so that if the user does not provide a value a default one will be used.
[Option('a', "address", DefaultValue = "http://me.com", Required = false, HelpText = "Address of server.")]
public string Address{ get; set; }
The issue I am facing is that the default value is specific for a given deployment and needs to be configured after deployment. I would like the user/administrator to be able to set the default value of these options using a configuration file.
Does anyone know how to change the default value for an option at run time? Then when starting the application I can load the configuration file and set the default values accordingly.
For the benefit of anyone else looking for this, I was facing the same issue today, and I realised that Options work fine with C# 6 Auto Property Initializers.
[Option]
public string MyProperty { get; set; } = Properties.Settings.Default.MySetting;
No doubt in C# 5 and earlier you could achieve the same thing with a private backing property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With