I'm using Configuration Binding in an ASP.NET Core 1.1 solution. Basically, I have some simple code for the binding in my ConfigureServices Startup section that looks like this:
services.AddSingleton(Configuration.GetSection("SettingsSection").Get<SettingsClass>());
The wrinkle is that my class as an int property that is normally bound to an int value in the configuration file, but could be bound instead to the string "disabled". Under the hood, I want the property to get a value of -1 if it is bound to the string "disabled".
It can be more complicated than this, but I'm simplifying for the sake of brevity.
My question is this: How do I provide a custom binder/converter for that overrides the configuration binding for a specific property in SettingsClass so that when doing a string conversion it will convert "disabled" to -1, rather than throwing an exception that "disabled" can't be converted to an Int32?