Exemple #1
0
        /// <summary>
        /// This method will return null if value is not found. Does not throw exception.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="paramName"></param>
        /// <returns></returns>
        private static T GetNullableReferenceTypeValue <T>(ConfigUtilKeys paramName) where T : class, IConvertible
        {
            string val = GetVal(paramName.Description()) + string.Empty;

            if (val != string.Empty)
            {
                return((T)Convert.ChangeType(val, typeof(T)));
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Use for non-nullable values. If the value is null, exception is thrown.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="paramName"></param>
        /// <returns></returns>
        private static T GetNonNullableParamValue <T>(ConfigUtilKeys paramName)
        {
            string val = GetVal(paramName.Description()) + string.Empty;

            if (val != string.Empty)
            {
                return((T)Convert.ChangeType(val, typeof(T)));
            }
            else
            {
                throw new ConfigurationErrorsException(
                          string.Format("Application Setting \"{0}\" is required for the application to function correctly.", paramName.Description()));
            }
        }