/// <summary> /// Parses and checks a number from the string. Throws LoadingException if the string is not a correct number. /// </summary> /// <param name="text">String to be parsed.</param> /// <param name="numberType">Input number type.</param> /// <returns>Parsed number from the given string.</returns> private int ParseAndCheckNumber(string text, InputNumberType numberType = InputNumberType.NonNegative) { int number; bool valid = int.TryParse(text, out number); if (!valid) { throw GetException($"Integer number expected, but '{text}' value found."); } if (number < 0) { if (numberType == InputNumberType.NonNegativeOrMinusOne) { if (number != -1) { throw GetException($"Non-negative integer or -1 number expected, but '{number}' found."); } } else { throw GetException($"Non-negative integer number expected, but '{number}' found."); } } return(number); }
/// <summary> /// Parses and checks a list of numbers from the string. Throws LoadingException if the string is not a correct list of numbers. /// </summary> /// <param name="text">String to be parsed.</param> /// <returns>Parsed list of numbers from the given string.</returns> private List <int> ParseAndCheckNumberList(string text) { List <int> retList = new List <int>(); string[] numbersList = SplitByWhiteSpaces(text); if (numbersList.Length <= 1) { throw GetException($"List of numbers expected, but '{text}' found."); } for (int i = 0; i < numbersList.Length; ++i) { InputNumberType inputNumberType = (i == numbersList.Length - 2) ? InputNumberType.NonNegativeOrMinusOne : InputNumberType.NonNegative; retList.Add(ParseAndCheckNumber(numbersList[i], inputNumberType)); } return(retList); }