예제 #1
0
 /// <summary>
 /// Parse a <see cref="KeySpline"/> from a string. The string
 /// needs to contain 4 values in it for the 2 control points.
 /// </summary>
 /// <param name="value">string with 4 values in it</param>
 /// <param name="culture">culture of the string</param>
 /// <exception cref="FormatException">Thrown if the string does not have 4 values</exception>
 /// <returns>A <see cref="KeySpline"/> with the appropriate values set</returns>
 public static KeySpline Parse(string value, CultureInfo culture)
 {
     using (var tokenizer = new StringTokenizer((string)value, CultureInfo.InvariantCulture, exceptionMessage: "Invalid KeySpline."))
     {
         return(new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble()));
     }
 }
        public void ReadDouble_Reads_Values()
        {
            var target = new StringTokenizer("12.3,45.6");

            Assert.Equal(12.3, target.ReadDouble());
            Assert.Equal(45.6, target.ReadDouble());
            Assert.Throws <FormatException>(() => target.ReadDouble());
        }
예제 #3
0
파일: Size.cs 프로젝트: soosr/Avalonia
 /// <summary>
 /// Parses a <see cref="Size"/> string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>The <see cref="Size"/>.</returns>
 public static Size Parse(string s)
 {
     using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Size."))
     {
         return(new Size(
                    tokenizer.ReadDouble(),
                    tokenizer.ReadDouble()));
     }
 }
예제 #4
0
 /// <summary>
 /// Parses a <see cref="Point"/> string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="culture">The current culture.</param>
 /// <returns>The <see cref="Thickness"/>.</returns>
 public static Point Parse(string s, CultureInfo culture)
 {
     using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Point"))
     {
         return(new Point(
                    tokenizer.ReadDouble(),
                    tokenizer.ReadDouble()
                    ));
     }
 }
예제 #5
0
파일: Rect.cs 프로젝트: xllance/Avalonia
 /// <summary>
 /// Parses a <see cref="Rect"/> string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>The parsed <see cref="Rect"/>.</returns>
 public static Rect Parse(string s)
 {
     using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Rect."))
     {
         return new Rect(
             tokenizer.ReadDouble(),
             tokenizer.ReadDouble(),
             tokenizer.ReadDouble(),
             tokenizer.ReadDouble()
         );
     }
 }
예제 #6
0
        /// <summary>
        /// Parse a <see cref="KeySpline"/> from a string. The string
        /// needs to contain 4 values in it for the 2 control points.
        /// </summary>
        /// <param name="value">string with 4 values in it</param>
        /// <param name="culture">culture of the string</param>
        /// <exception cref="FormatException">Thrown if the string does not have 4 values</exception>
        /// <returns>A <see cref="KeySpline"/> with the appropriate values set</returns>
        public static KeySpline Parse(string value, CultureInfo culture)
        {
            if (culture is null)
            {
                culture = CultureInfo.InvariantCulture;
            }

            using (var tokenizer = new StringTokenizer((string)value, culture, exceptionMessage: $"Invalid KeySpline string: \"{value}\"."))
            {
                return(new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble()));
            }
        }
예제 #7
0
        /// <summary>
        /// Parses a <see cref="Thickness"/> string.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <param name="culture">The current culture.</param>
        /// <returns>The <see cref="Thickness"/>.</returns>
        public static Thickness Parse(string s, CultureInfo culture)
        {
            using (var tokenizer = new StringTokenizer(s, culture, exceptionMessage: "Invalid Thickness"))
            {
                var a = tokenizer.ReadDouble();

                if (tokenizer.TryReadDouble(out var b))
                {
                    if (tokenizer.TryReadDouble(out var c))
                    {
                        return(new Thickness(a, b, c, tokenizer.ReadDouble()));
                    }

                    return(new Thickness(a, b));
                }

                return(new Thickness(a));
            }
        }
예제 #8
0
        /// <summary>
        /// Parses a <see cref="Matrix"/> string.
        /// </summary>
        /// <param name="s">Six or nine comma-delimited double values (m11, m12, m21, m22, offsetX, offsetY[, persX, persY, persZ]) that describe the new <see cref="Matrix"/></param>
        /// <returns>The <see cref="Matrix"/>.</returns>
        public static Matrix Parse(string s)
        {
            // initialize to satisfy compiler - only used when retrieved from string.
            double v8 = 0;
            double v9 = 0;

            using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Matrix."))
            {
                var v1   = tokenizer.ReadDouble();
                var v2   = tokenizer.ReadDouble();
                var v3   = tokenizer.ReadDouble();
                var v4   = tokenizer.ReadDouble();
                var v5   = tokenizer.ReadDouble();
                var v6   = tokenizer.ReadDouble();
                var pers = tokenizer.TryReadDouble(out var v7);
                pers = pers && tokenizer.TryReadDouble(out v8);
                pers = pers && tokenizer.TryReadDouble(out v9);

                if (pers)
                {
                    return(new Matrix(v1, v2, v7, v3, v4, v8, v5, v6, v9));
                }
                else
                {
                    return(new Matrix(v1, v2, v3, v4, v5, v6));
                }
            }
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var points = new List <Point>();

            using (var tokenizer = new StringTokenizer((string)value, CultureInfo.InvariantCulture, exceptionMessage: "Invalid PointsList."))
            {
                while (tokenizer.TryReadDouble(out double x))
                {
                    points.Add(new Point(x, tokenizer.ReadDouble()));
                }
            }

            return(points);
        }
예제 #10
0
        /// <summary>
        /// Parses a <see cref="Thickness"/> string.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <returns>The <see cref="Thickness"/>.</returns>
        public static Thickness Parse(string s)
        {
            using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage: "Invalid Thickness"))
            {
                if (tokenizer.TryReadDouble(out var a))
                {
                    if (tokenizer.TryReadDouble(out var b))
                    {
                        if (tokenizer.TryReadDouble(out var c))
                        {
                            return(new Thickness(a, b, c, tokenizer.ReadDouble()));
                        }

                        return(new Thickness(a, b));
                    }

                    return(new Thickness(a));
                }

                throw new FormatException("Invalid Thickness.");
            }
        }
예제 #11
0
        public static CornerRadius Parse(string s)
        {
            const string exceptionMessage = "Invalid CornerRadius.";

            using (var tokenizer = new StringTokenizer(s, CultureInfo.InvariantCulture, exceptionMessage))
            {
                if (tokenizer.TryReadDouble(out var a))
                {
                    if (tokenizer.TryReadDouble(out var b))
                    {
                        if (tokenizer.TryReadDouble(out var c))
                        {
                            return(new CornerRadius(a, b, c, tokenizer.ReadDouble()));
                        }

                        return(new CornerRadius(a, b));
                    }

                    return(new CornerRadius(a));
                }

                throw new FormatException(exceptionMessage);
            }
        }