예제 #1
0
        private static bool TryGetValue(PropertyInfo propertyInfo, Configuration configuration, out object result)
        {
            result = null;

            var type          = propertyInfo.PropertyType;
            var reflectedType = propertyInfo.ReflectedType;
            var keys          = new[]
            {
                reflectedType.Name + propertyInfo.Name,
                propertyInfo.Name,
            };

            var vals = from key in keys
                       let attempt = type == typeof(ConnectionStringSettings) ? configuration.ConnectionString.Get(key)
                                                                              : configuration.ConvertValue(type, configuration.Get(key))
                                     where attempt != null
                                     select attempt;

            foreach (var value in vals)
            {
                result = value;
                return(true);
            }
            return(false);
        }
예제 #2
0
 private static object GetValueOrNull(Type type, string key, Configuration configuration)
 {
     try
     {
         return(type == typeof(ConnectionStringSettings) ? configuration.ConnectionString.Get(key)
                                                         : configuration.ConvertValue(type, configuration.Get(key)));
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
 }