public static bool TryParse()

in src/Avalonia.Base/Media/Color.cs [208:268]


        public static bool TryParse(ReadOnlySpan<char> s, out Color color)
        {
            if (s.Length == 0)
            {
                color = default;
                return false;
            }

            if (s[0] == '#' &&
                TryParseHexFormat(s, out color))
            {
                return true;
            }

            // At this point all parsing uses strings
            var str = s.ToString();

            // Note: The length checks are also an important optimization.
            // The shortest possible CSS format is "rbg(0,0,0)", Length = 10.

            if (s.Length >= 10 &&
                (s[0] == 'r' || s[0] == 'R') &&
                (s[1] == 'g' || s[1] == 'G') &&
                (s[2] == 'b' || s[2] == 'B') &&
                TryParseCssFormat(str, out color))
            {
                return true;
            }

            if (s.Length >= 10 &&
                (s[0] == 'h' || s[0] == 'H') &&
                (s[1] == 's' || s[1] == 'S') &&
                (s[2] == 'l' || s[2] == 'L') &&
                HslColor.TryParse(str, out HslColor hslColor))
            {
                color = hslColor.ToRgb();
                return true;
            }

            if (s.Length >= 10 &&
                (s[0] == 'h' || s[0] == 'H') &&
                (s[1] == 's' || s[1] == 'S') &&
                (s[2] == 'v' || s[2] == 'V') &&
                HsvColor.TryParse(str, out HsvColor hsvColor))
            {
                color = hsvColor.ToRgb();
                return true;
            }

            var knownColor = KnownColors.GetKnownColor(str);

            if (knownColor != KnownColor.None)
            {
                color = knownColor.ToColor();
                return true;
            }

            color = default;

            return false;
        }