using System.Collections.Generic;
public static void Main()
var flags = EnumHelper.GetFlags(typeof(A), 3);
Console.WriteLine(string.Join(", ", flags));
public static IEnumerable<Enum> GetFlags(Type enumType, int value)
throw new ArgumentNullException(nameof(enumType));
throw new ArgumentException(string.Empty, nameof(enumType));
var attribute = enumType.GetCustomAttribute<FlagsAttribute>();
throw new ArgumentException(string.Empty, nameof(enumType));
var enumValue = (Enum) Enum.ToObject(enumType, value);
return from Enum enumVal in enumType.GetEnumValues()
where enumValue.HasFlag(enumVal)