using System.Diagnostics;
public static void Main()
var stopWatch = new Stopwatch();
Console.WriteLine("Starting");
var currentStatus = Status.IsIncomplete | Status.IsNonConformant;
for(int i = loops; i > 0; i--)
currentStatus.HasFlag(Status.IsIncomplete);
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
Console.WriteLine("RunTime for boxing" + elapsedTime);
for(int i = loops; i > 0; i--)
EnumExtensions.ContainsFlag(currentStatus,Status.IsIncomplete);
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
Console.WriteLine("RunTime for reflection" + elapsedTime);
RequiresReconciliation = 64,
RequiresVerification = 128,
RequiresAnswerQuery = 16384,
RequiresPendingCloseQuery = 32768,
RequiresCloseQuery = 65536,
IsSignatureNotCurrent = 524288,
RequiresTranslation = 1048576,
RequiresCoding = 2097152,
RequiresPendingAnswerQuery = 4194304,
RequiresSignature = 8388608,
PageReadyForFreeze = 33554432,
PageReadyForLock = 67108864,
RequiresCancelQuery = 134217728,
RequiresCoderCoding = 268435456
internal static class EnumHelper<T1>
public static Func<T1, T1, bool> TestOverlapProc = initProc;
public static bool Overlaps(SByte p1, SByte p2) { return (p1 & p2) == p2; }
public static bool Overlaps(Byte p1, Byte p2) { return (p1 & p2) == p2; }
public static bool Overlaps(Int16 p1, Int16 p2) { return (p1 & p2) == p2; }
public static bool Overlaps(UInt16 p1, UInt16 p2) { return (p1 & p2) == p2; }
public static bool Overlaps(Int32 p1, Int32 p2) { return (p1 & p2) == p2; }
public static bool Overlaps(UInt32 p1, UInt32 p2) { return (p1 & p2) == p2; }
public static bool Overlaps(Int64 p1, Int64 p2) { return (p1 & p2) == p2; }
public static bool Overlaps(UInt64 p1, UInt64 p2) { return (p1 & p2) == p2; }
public static bool initProc(T1 p1, T1 p2)
if (typ1.IsEnum) typ1 = Enum.GetUnderlyingType(typ1);
Type[] types = { typ1, typ1 };
var method = typeof(EnumHelper<T1>).GetMethod("Overlaps", types);
if (method == null) method = typeof(T1).GetMethod("Overlaps", types);
if (method == null) throw new MissingMethodException("Unknown type of enum");
TestOverlapProc = (Func<T1, T1, bool>)Delegate.CreateDelegate(typeof(Func<T1, T1, bool>), method);
return TestOverlapProc(p1, p2);
static class EnumExtensions
public static bool ContainsFlag<T>(this T p1, T p2) where T : struct
return EnumHelper<T>.TestOverlapProc(p1, p2);