public override object Read(IConfiguration configuration, Type configType, IKeyName keyName) { var valueType = configType.GetGenericTypeOfConfigurationSetting(); var elementType = valueType.GetElementType(); var key = keyName.QualifiedKeyName; // Making sure the section exists if (!configuration.GetSection(key).Exists()) { // Return null if no section exists StaticLoggingHelper.Warning($"No configuration for '{key}' was found."); return(null); } // Handle Complex Arrays if (valueType.IsArray && elementType != null && !elementType.IsValueType) { return(configuration.GetSection(key).GetChildren() .Select(config => config.Get(elementType)) .ToArray()); } return(configuration.GetSection(key).Get(valueType)); }
public override object Read(IConfiguration configuration, Type complexType, IKeyName keyName) { var key = keyName.QualifiedKeyName; // return null if no section exists if (!ValueExists(configuration, complexType, keyName)) { StaticLoggingHelper.Warning($"No configuration for '{key}' was found."); return(null); } return(configuration.GetSection(key).Get(complexType)); }
public override object Read(IConfiguration configuration, Type configType, IKeyName keyName) { var key = keyName.QualifiedKeyName; var valueType = configType.GetGenericTypeOfConfigurationSetting(); // Making sure the section exists if (!ValueExists(configuration, configType, keyName)) { // Return default value if no section exists StaticLoggingHelper.Warning($"No configuration for '{key}' was found."); return(GetDefault(valueType)); } return(configuration.GetSection(key).Get(valueType)); }
public abstract object Read(IConfiguration configuration, Type configType, IKeyName keyName);
public bool ValueExists(IConfiguration configuration, Type configType, IKeyName keyName) { var key = keyName.QualifiedKeyName; return(configuration.GetSection(key).Exists()); }
public ConfigurationSettingMissingException(Type configType, IKeyName keyName) : base($"{configType.Name} couldn't be read from configuration using key: {keyName.QualifiedKeyName}") { }