예제 #1
0
        public bool ParameterInputIsEnum(string i_Parameter, out string o_EnumStringValue)
        {
            bool isParameterInputNotString = false;

            o_EnumStringValue = null;
            switch (i_Parameter)
            {
            case "Color":
                o_EnumStringValue         = EnumOperations.ListEnumValues <eColor>(true);
                isParameterInputNotString = true;
                break;

            case "Number Of Doors":
                o_EnumStringValue         = EnumOperations.ListEnumValues <eNumOfDoors>(true);
                isParameterInputNotString = true;
                break;

            case "License Type":
                o_EnumStringValue         = EnumOperations.ListEnumValues <eLicenseType>(true);
                isParameterInputNotString = true;
                break;

            case "if it Contains Dangerous Materials":
                o_EnumStringValue         = string.Format("Yes{0}No", Environment.NewLine);
                isParameterInputNotString = true;
                break;
            }

            return(isParameterInputNotString);
        }
예제 #2
0
        public static T ValidateAndParseEnum <T>(string i_EnumValue) where T : struct
        {
            if (!Enum.TryParse <T>(i_EnumValue, out T enumValue) || !Enum.GetNames(typeof(T)).Contains(i_EnumValue))
            {
                bool enumListWithNumbers = false;
                throw new FormatException(string.Format("Invalid Choice. Enter one of the following: {0}", EnumOperations.ListEnumValues <T>(enumListWithNumbers)));
            }

            return(enumValue);
        }