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));
        }
示例#2
0
        private string ToString(string format, IFormatProvider provider)
        {
            if (IsEmpty)
            {
                return("Empty");
            }

            if (provider == null)
            {
                provider = CultureInfo.CurrentCulture;
            }

            if (format == null)
            {
                format = string.Empty;
            }

            var separator = NumericListTokenizer.GetSeparator(provider);

            var rectFormat = string.Format(
                "{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}",
                format, separator);

            return(string.Format(provider, rectFormat,
                                 _x, _y, _width, _height));
        }
示例#3
0
文件: Point.cs 项目: Tsalex71/mono-1
        private string ToString(string format, IFormatProvider formatProvider)
        {
            if (formatProvider == null)
            {
                formatProvider = CultureInfo.CurrentCulture;
            }
            if (format == null)
            {
                format = string.Empty;
            }
            var separator   = NumericListTokenizer.GetSeparator(formatProvider);
            var pointFormat = string.Format("{{0:{0}}}{1}{{1:{0}}}", format, separator);

            return(string.Format(formatProvider, pointFormat, _x, _y));
        }
示例#4
0
文件: Point.cs 项目: Tsalex71/mono-1
        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));
        }
示例#5
0
        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);
        }