using System.Collections.Generic;
public static class EnumHelper
public static IEnumerable<T> GetFlagValues<T>(this Enum flags) where T: Enum
return Enum.GetValues(typeof(T))
.Where(x => flags.HasFlag(x));
private static void PrintMixedColorsInfo(string name, Colors color)
IEnumerable<string> colors = color.GetFlagValues<Colors>().Except(new [] { Colors.None } ).Select(x => x.ToString());
Console.WriteLine("Color \"" + name + "\" is not mixed. It's a primary color.");
Console.WriteLine("Color \"" + name + "\" is mixed by: " + string.Join(" | ", colors));
public static void Main()
var colors = new Dictionary<string, Colors>()
{ "green", Colors.Yellow | Colors.Blue },
{ "orange", Colors.Yellow | Colors.Red },
{ "purple", Colors.Blue | Colors.Red },
{ "brown", Colors.Yellow | Colors.Blue | Colors.Red },
{ "light green", Colors.Blue | Colors.Yellow | Colors.White },
{ "light orange", Colors.Yellow | Colors.Red | Colors.White },
foreach(var color in colors)
PrintMixedColorsInfo(color.Key, color.Value);