Skip to content

resgroup/configuration

Repository files navigation

Configuration

A C# library for strongly typed Configuration with validation. Please see Taming Configuration in C# for more details.

Build status

codecov

Example Usage (Configuration is the class provided by this repo)

public class EconomicModelConfiguration, ICurrencyConversionConfiguration, IConcreteCostConfiguration 
{
    readonly Configuration configuration;
    
    public EconomicModelConfiguration(Configuration configuration) {
        Contract.Requires(configuration != null);

        this.configuration = configuration;
    
        Validate();
    }
    
    void Validate() {
        using (var validator = configuration.CreateValidator) {
            validator.Check(() => DefaultCurrency);
            validator.Check(() => DefaultConcreteCost);
        }
    }

    public string DefaultCurrency => 
        configuration.GetEnum<Currency>(MethodBase.GetCurrentMethod());

    public double DefaultConcreteCost => 
        configuration.GetDouble(MethodBase.GetCurrentMethod());
}