private static IList <Exception> LookupAndSetValuesFor(PropertyInfo[] properties, string rootName, IDictionary <string, object> expando)
        {
            var problems = new List <Exception>();

            foreach (var property in properties)
            {
                var key = rootName + "." + property.Name;

                var unparsedValue = GetValueFor(key);

                if (unparsedValue.HasValue)
                {
                    try
                    {
                        var value = ConvertValue.To(unparsedValue.Value, property.PropertyType);
                        expando[property.Name] = value;
                    }
                    catch (Exception e)
                    {
                        problems.Add(new SettingConversionException(key, unparsedValue.Value, property.PropertyType, e));
                        expando[property.Name] = unparsedValue.Value;
                    }
                }

                if (expando[property.Name] == null)
                {
                    problems.Add(new SettingNotFoundException(key, ValueStrategies.Keys));
                }
            }

            return(problems);
        }
Exemple #2
0
        public static T Get <T>(string key)
        {
            var rawValue = Configuration.GetValueFor(key);

            try
            {
                if (rawValue.HasValue)
                {
                    return(ConvertValue.To <T>(rawValue.Value));
                }
                throw new Exception("?");
            }
            catch (Exception e)
            {
                //TODO: add info about key
                throw;
            }
        }