public static Size Parse(string source) { if (source == null) { throw new ArgumentNullException("source"); } if (source.Trim() == "Empty") { return(Empty); } var tokenizer = new NumericListTokenizer(source, CultureInfo.InvariantCulture); double width; double height; if (!double.TryParse(tokenizer.GetNextToken(), NumberStyles.Float, CultureInfo.InvariantCulture, out width) || !double.TryParse(tokenizer.GetNextToken(), NumberStyles.Float, CultureInfo.InvariantCulture, out height)) { throw new FormatException(string.Format("Invalid Size format: {0}", source)); } if (!tokenizer.HasNoMoreTokens()) { throw new InvalidOperationException("Invalid Size format: " + source); } return(new Size(width, height)); }
public static Point Parse(string source) { if (source == null) { throw new ArgumentNullException("source"); } var tokenizer = new NumericListTokenizer(source, CultureInfo.InvariantCulture); double x; double y; if (!double.TryParse(tokenizer.GetNextToken(), NumberStyles.Float, CultureInfo.InvariantCulture, out x) || !double.TryParse(tokenizer.GetNextToken(), NumberStyles.Float, CultureInfo.InvariantCulture, out y)) { throw new FormatException(string.Format("Invalid Point format: {0}", source)); } if (!tokenizer.HasNoMoreTokens()) { throw new InvalidOperationException("Invalid Point format: " + source); } return(new Point(x, y)); }
public static Int32Rect Parse(string source) { if (source == null) { throw new ArgumentNullException("source"); } Int32Rect value; if (source.Trim() == "Empty") { value = Empty; } else { var tokenizer = new NumericListTokenizer(source, CultureInfo.InvariantCulture); int x; int y; int width; int height; if (int.TryParse(tokenizer.GetNextToken(), NumberStyles.Integer, CultureInfo.InvariantCulture, out x) && int.TryParse(tokenizer.GetNextToken(), NumberStyles.Integer, CultureInfo.InvariantCulture, out y) && int.TryParse(tokenizer.GetNextToken(), NumberStyles.Integer, CultureInfo.InvariantCulture, out width) && int.TryParse(tokenizer.GetNextToken(), NumberStyles.Integer, CultureInfo.InvariantCulture, out height)) { if (!tokenizer.HasNoMoreTokens()) { throw new InvalidOperationException("Invalid Int32Rect format: " + source); } value = new Int32Rect(x, y, width, height); } else { throw new FormatException(string.Format("Invalid Int32Rect format: {0}", source)); } } return(value); }