Ejemplo n.º 1
0
 public static T GetPropertyOrDefault <T>(this IConfigurationObject configurationObject, string propertyName)
 {
     if (!configurationObject.HasProperty(propertyName))
     {
         return(default(T));
     }
     return(TypeHelper.ConvertType <T>(configurationObject.GetProperty(propertyName)));
 }
Ejemplo n.º 2
0
        public static T GetOrCreateProperty <T>(this IConfigurationObject configurationObject, string propertyName, Func <T> propertyConstructor)
            where T : class
        {
            T property;

            if (propertyConstructor == null)
            {
                throw new ArgumentNullException("propertyConstructor");
            }
            if (configurationObject.HasProperty(propertyName))
            {
                property = (T)(configurationObject.GetProperty(propertyName) as T);
                if (property != null)
                {
                    return(property);
                }
            }
            property = propertyConstructor();
            configurationObject.SetProperty(propertyName, property);
            return(property);
        }