public static Element Parse(string input) { if (input.Contains(" ")) { throw new ArgumentException(string.Format("Spaces are not allowed in individual elements. Tried to parse {0}.", input), "input"); } Element result; if (input.IsDecimalNumber()) { result = new Element(input, ElementType.DecimalNumber, Operator.NotAnOperator); } else if (input.IsHexadecimalNumber()) { result = new Element(input, ElementType.HexadecimalNumber, Operator.NotAnOperator); } else if (input.IsBinaryNumber()) { result = new Element(input, ElementType.BinaryNumber, Operator.NotAnOperator); } else if (input.IsOctalNumber()) { result = new Element(input, ElementType.OctalNumber, Operator.NotAnOperator); } else if (input.IsUnaryOperator()) { throw new ArgumentException("Cannot parse a single unary operator.", "input"); } else if (input.IsBinaryOperator()) { result = new Element(input, ElementType.BinaryOperator, input.GetBinaryOperator()); } else if (input.IsDecimalNumberWithUnaryOperators()) { throw new ArgumentException("Cannot parse a number with unary operators.", "input"); } throw new ArgumentException(string.Format("Could not recognize the input to parse. Input: \"{0}\"", input), "input"); }