- if (knownColors == null)
- FillColorNames ();
-
- if (c < KnownColor.ActiveBorder || c > KnownColor.YellowGreen) {
- // This is what it returns!
- Color d = FromArgb (0, 0, 0, 0);
- d.myname = c.ToString ();
- d.colorType |= ColorType.Named;
- d.knownColor = c;
- return d;
- }
-
- return knownColors [(int) c];
- }
-
- private static Hashtable GetColorHashtableFromType (Type type)
- {
- Hashtable colorHash = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
- CaseInsensitiveComparer.Default);
-
- PropertyInfo [] props = type.GetProperties ();
- foreach (PropertyInfo prop in props){
- if (prop.PropertyType != typeof (Color))
- continue;
-
- MethodInfo getget = prop.GetGetMethod ();
- if (getget == null || getget.IsStatic == false)
- continue;
-
- object o = prop.GetValue (null, null);
- colorHash.Add (prop.Name, o);
-
- Color c = (Color) o;
- knownColors [(int) c.knownColor] = c;
- }
- return colorHash;
- }
-
- private static void FillColorNames ()
- {
- if (systemColors != null)
- return;
-
- lock (creatingColorNames) {
- if (systemColors != null)
- return;
-
- knownColors = new Color [(int)KnownColor.YellowGreen + 1];
-
- Hashtable colorHash = GetColorHashtableFromType (typeof (Color));
- namedColors = colorHash;
-
- colorHash = GetColorHashtableFromType (typeof (SystemColors));
- systemColors = colorHash;
- }