Example #1
0
        /// Parses a string after validating it and returns
        /// the value of the enumeration it represents.
        /// <param name="lookup">Enumeration lookup.</param>
        /// <param name="enumType">Type of enumeration.</param>
        /// <param name="val">Value of string.</param>
        /// <param name="results">Validation results.</param>
        /// <param name="defaultValue">Default value.</param>
        /// <returns>Enumeration value.</returns>
        public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results, string defaultValue)
        {
            // Invalid enum value.
            if (!EnumLookup.IsValid(enumType, val))
            {
                results.Add("Invalid value '" + val + "' for " + enumType.Name);
                return(false);
            }

            return(EnumLookup.GetValue(enumType, val, defaultValue));
        }
Example #2
0
 /// <summary>
 /// Parses a string after validating it and returns
 /// the value of the enumeration it represents.
 /// </summary>
 /// <param name="lookup">Enumeration lookup.</param>
 /// <param name="enumType">Type of enumeration.</param>
 /// <param name="val">Value of string.</param>
 /// <param name="results">Validation results.</param>
 /// <returns>Enumeration value.</returns>
 public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results)
 {
     return(GetValue(lookup, enumType, val, results, string.Empty));
 }