public static eLicensType GetLicenseType() { string typeOfLicenseFromUser = Console.ReadLine(); while (true) { try { eLicensType eLicenseType = (eLicensType)Enum.Parse(typeof(eLicensType), typeOfLicenseFromUser); if ((int)eLicenseType > (int)Enum.GetValues(typeof(eLicensType)).Cast <eLicensType>().Last()) { throw new ValueOutOfRangeException(4, 1); } return(eLicenseType); } catch (ArgumentException ex) { Console.WriteLine(@"Wrong input due to {0},please enter A(1)/A1(2)/A2(3)/B(4)", ex.Message); typeOfLicenseFromUser = Console.ReadLine(); } catch (ValueOutOfRangeException ex) { Console.WriteLine(ex.Message); typeOfLicenseFromUser = Console.ReadLine(); } } }
public override void UpdateSpecificPropeties(string i_LicenseTypeFromUser, string i_EngineVolumeFromUser) { bool isParseAble = false; m_LicenseType = (eLicensType)Enum.Parse(typeof(eLicensType), i_LicenseTypeFromUser); if ((int)m_LicenseType > (int)Enum.GetValues(typeof(eLicensType)).Cast <eLicensType>().Last() || m_LicenseType < 0) { throw new ValueOutOfRangeException(4, 1, "License Type"); } isParseAble = int.TryParse(i_EngineVolumeFromUser, out m_EngineVolume); if (isParseAble) { if (m_EngineVolume < 0 || m_EngineVolume > 10000) { throw new ValueOutOfRangeException(10000, 0, "Engine Volume"); } } else { throw new FormatException(); } }