private static bool TryParseColor(ref Color color, ColorRepresentanion colorRep, string text) { bool result = false; switch (colorRep) { case ColorRepresentanion.None: result = false; break; case ColorRepresentanion.Hex: string hexRepresentation = GetHexNumber(text); color = ColorTranslator.FromHtml(hexRepresentation); result = true; break; case ColorRepresentanion.CommaSeperated: result = TryParseCommaSeperatedColor(ref color, text); break; default: result = false; break; } return(result); }
public static bool TryGetColor(string colorName, out Color color) { color = Color.Empty; ColorRepresentanion colorRep = ClassifyColor(colorName); return(TryParseColor(ref color, colorRep, colorName)); }
private static ColorRepresentanion ClassifyColor(string text) { ColorRepresentanion colorRep = ColorRepresentanion.None; if (text.Contains(',')) { colorRep = ColorRepresentanion.CommaSeperated; } else { colorRep = ColorRepresentanion.Hex; } //if (text.StartsWith("#") || text.StartsWith("$") || IsHexLetters(text)) // colorRep = ColorRepresentanion.Hex; //colorRep = ColorRepresentanion.Hex; return(colorRep); }