Ejemplo n.º 1
0
        /// <summary>
        /// Parses a brush string.
        /// </summary>
        /// <param name="s">The brush string.</param>
        /// <returns>The <see cref="Color"/>.</returns>
        public static IBrush Parse(string s)
        {
            Contract.Requires <ArgumentNullException>(s != null);
            Contract.Requires <FormatException>(s.Length > 0);

            if (s[0] == '#')
            {
                return(new ImmutableSolidColorBrush(Color.Parse(s)));
            }

            var brush = KnownColors.GetKnownBrush(s);

            if (brush != null)
            {
                return(brush);
            }

            throw new FormatException($"Invalid brush string: '{s}'.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses a brush string.
        /// </summary>
        /// <param name="s">The brush string.</param>
        /// <returns>The <see cref="Color"/>.</returns>
        public static IBrush Parse(string s)
        {
            _ = s ?? throw new ArgumentNullException(nameof(s));

            if (s.Length > 0)
            {
                if (s[0] == '#')
                {
                    return(new ImmutableSolidColorBrush(Color.Parse(s)));
                }

                var brush = KnownColors.GetKnownBrush(s);
                if (brush != null)
                {
                    return(brush);
                }
            }

            throw new FormatException($"Invalid brush string: '{s}'.");
        }