runtime: System.Drawing.Color is possibly missing 8 colors

Background and Motivation

It appears that the System.Drawing.Color names are intended to track the CSS color names; if that is correct, there are some colors which need to be added. Two reasons for thinking the names are supposed to track CSS colors are:

Proposed API

Affecting at least KnownColor.cs and KnownColorNames.cs and KnownColorTable.cs and Affecting at least Color.cs, the significant differences are the addition of the new RebeccaPurple color, and the variant spellings of grAy colors as grEy:


namespace System.Drawing
{
    enum KnownColor
    {
+    RebeccaPurple,
+    DarkGrey,
+    DarkSlateGrey,
+    DimGrey,
+    Grey,
+    LightGrey,
+    LightSlateGrey,
+    SlateGrey,
     }

    public readonly struct Color : IEquatable<Color>
    {
+    public static Color RebeccaPurple;
+    public static Color DarkGrey;
+    public static Color DarkSlateGrey;
+    public static Color DimGrey;
+    public static Color Grey;
+    public static Color LightGrey;
+    public static Color LightSlateGrey;
+    public static Color SlateGrey;
    }
}

Possibly related, System.Windows.Media.Colors

Usage Examples

using System.Drawing;

string text = String.Format(
    "The CSS color 'RebeccaPurple' has Red component of {0}", 
    Color.RebeccaPurple.R);

Alternative Designs

I have not considered any particular designs, only intending to report this as a bug where the existing behaviour differs from the intended behaviour.

Risks

This will change the total number of items in the Color enum, and (depending on whether the new ones are added in order, or to the end) might change the existing color locations.


I think the missing color values are:

  • RebeccaPurple #663399
  • DarkGrey #a9a9a9
  • DarkSlateGrey #2f4f4f
  • DimGrey #696969
  • Grey #808080
  • LightGrey #d3d3d3
  • LightSlateGrey #778899
  • SlateGrey #708090

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (26 by maintainers)

Commits related to this issue

Most upvoted comments

If the .Net colors are not intended to track the CSS colors

I’m not sure if it has been our intention over the past, but I think it doesn’t hurt to add those colors if they help matching other frameworks with default colors.

Marked as ready for review.

I think supporting parsing both without exposing both would be reasonable. We can then chalk the existing duplicates up as legacy/back-compat

Do we still think we want to address the gray vs. grey colors or should we close this issue?

I think we should add the aliases as @tannergooding mentioned.

cc @safern @tannergooding who are area owners and will have a more interesting response than me.

Given that these are largely the W3C color types, that we define other aliases such as aqua/cyan and fuchsia/magenta, and that we have existing special handling for at least one grey vs gray; I think it would be worthwhile to add the other aliases and just spec it out as explicitly mapping to the W3C color name/values defined for CSS: https://www.w3.org/wiki/CSS/Properties/color/keywords (the docs currently link to https://developer.mozilla.org/en-US/docs/Web/CSS/color_value in a couple places).

i want to try implementing this