YAMP.Converter.StringToEnumConverter.StringToEnumConverter C# (CSharp) Method

StringToEnumConverter() public method

Creates a new String to Enumeration (value) converter.
public StringToEnumConverter ( Type enumType ) : System
enumType System.Type The enumeration which contains the possible values.
return System
        public StringToEnumConverter(Type enumType)
            : base(typeof(StringValue))
        {
            Converter = w =>
            {
                var str = (w as StringValue).Value;

                try
                {
                    return Enum.Parse(enumType, str, true);
                }
                catch
                {
                    var possibilites = enumType.GetFields(BindingFlags.Public | BindingFlags.Static).Select(fi => fi.Name).ToArray();
                    throw new YAMPArgumentValueException(str, possibilites);
                }
            };
        }
StringToEnumConverter