public static ArgbColor Parse(string s)
{
if (s[0] == '#')
{
var or = 0u;
if (s.Length == 7)
{
or = 0xff000000;
}
else if (s.Length != 9)
{
throw new FormatException($"Invalid color string: '{s}'.");
}
return FromUInt32(uint.Parse(s.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture) | or);
}
else
{
var upper = s.ToUpperInvariant();
var member = typeof(Colors).GetTypeInfo().DeclaredProperties.FirstOrDefault(x => x.Name.ToUpperInvariant() == upper);
if (member != null)
{
return (ArgbColor)member.GetValue(null);
}
else
{
throw new FormatException($"Invalid color string: '{s}'.");
}
}
}