public IEnumerable <Color> GetAvailableColors() { RecalculateProperty(KnownColors); return(KnownColors .Where(color => color.Value.GetValueOrDefault(true)) .Select(color => color.Key)); }
public static string AsText(this Color c) { bool ColorEquals(KeyValuePair <string, Color> kv) { var c2 = kv.Value; return(c2.A == c.A && c2.R == c.R && c2.G == c.G && c2.B == c.B); } var l = KnownColors.Where(ColorEquals); using (var en = l.GetEnumerator()) { if (en.MoveNext()) { return(en.Current.Key); } } StringBuilder result = new StringBuilder(); result.Append("#"); if (c.A != 255) { result.Append($"{c.A:x2}"); } result.Append($"{c.R:x2}"); result.Append($"{c.G:x2}"); result.Append($"{c.B:x2}"); return(result.ToString()); }
private static string GetColorName(Color color) { return(KnownColors.Where(kvp => kvp.Value.Equals(color)) .Select(kvp => kvp.Key) .FirstOrDefault()); }