private static IDictionary <Type, TypeCode> InitTypeToTypeCodeLookupTable()
        {
            Dictionary <Type, TypeCode> result = new Dictionary <Type, TypeCode>();

            foreach (var pair in EnumUtility.ToEnumerable <TypeCode>())
            {
                try
                {
                    Type validType = Type.GetType(string.Format("System.{0}", pair.Value), false);
                    if (validType != null)
                    {
                        result.Add(validType, EnumUtility.Parse <TypeCode>(pair.Value));
                    }
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Converts the string representation of the name or numeric <paramref name="value"/> of one or more enumerated constants to an equivalent enumerated <typeparamref name="TEnum"/>.
 /// </summary>
 /// <typeparam name="TEnum">The type of the enumeration to convert.</typeparam>
 /// <param name="value">A string containing the name or value to convert.</param>
 /// <param name="ignoreCase"><c>true</c> to ignore case; <c>false</c> to regard case.</param>
 /// <returns>An enum of type <typeparamref name="TEnum" /> whose value is represented by <paramref name="value" />.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="value"/> is null.
 /// </exception>
 /// <exception cref="TypeArgumentException">
 /// <typeparamref name="TEnum"/> does not represents an enumeration.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// <paramref name="value"/> does not represents an enumeration.
 /// </exception>
 public static TEnum ToEnum <TEnum>(this string value, bool ignoreCase) where TEnum : struct, IConvertible
 {
     return(EnumUtility.Parse <TEnum>(value, ignoreCase));
 }