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));
        }
示例#4
0
 public abstract object Read(IConfiguration configuration, Type configType, IKeyName keyName);
示例#5
0
        public bool ValueExists(IConfiguration configuration, Type configType, IKeyName keyName)
        {
            var key = keyName.QualifiedKeyName;

            return(configuration.GetSection(key).Exists());
        }
示例#6
0
 public ConfigurationSettingMissingException(Type configType, IKeyName keyName) :
     base($"{configType.Name} couldn't be read from configuration using key: {keyName.QualifiedKeyName}")
 {
 }