public enum General : int
static public class ExtensionMethods
static public General ToGeneral<T>(this T input) where T : struct, IConvertible
if (!typeof(T).IsEnum) throw new ArgumentException("Input must be an enum.");
return (General)((int)(object)input & Enum.GetValues(typeof(General)).Cast<int>().Sum());
static public T ToEnum<T>(this General input)
if (!typeof(T).IsEnum) throw new ArgumentException("Output type must be an enum.");
return (T)Enum.ToObject(typeof(T), (int)input & Enum.GetValues(typeof(T)).Cast<int>().Sum());
static public TOut Convert<TIn,TOut>(TIn input) where TIn : struct, IConvertible where TOut: struct, IConvertible
var general = input.ToGeneral();
return general.ToEnum<TOut>();
public static void Main()
A valAsA = A.One | A.Three | A.Four;
B valAsB = Convert<A,B>(valAsA);
C valAsC = Convert<A,C>(valAsA);
Console.WriteLine("{0} should equal {1}", valAsB, (B.Three | B.Four));
Console.WriteLine("{0} should equal {1}", valAsC, (C.One | C.Three));