public static void HasFlagTest(TestFlags value, TestFlags flag) { // ReSharper disable HeapView.BoxingAllocation Assert.Equal(value.HasFlag(flag), EnumUtils <TestFlags> .HasFlag(value, flag)); Assert.Equal(value.HasFlag(flag), value.HasFlagF(flag)); // ReSharper restore HeapView.BoxingAllocation }
public void HasEnumFlags_NoApiConflicts() { TestFlags flags = TestFlags.One | TestFlags.Four; flags.HasFlag(TestFlags.Four) .Should().BeTrue(); }
static void Main(string[] args) { TestFlags f = TestFlags.Five; /* or any other enum */ bool result = false; Stopwatch s = Stopwatch.StartNew(); for (int i = 0; i < 10000000; i++) { result |= f.HasFlag(TestFlags.Three); } s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); // *4793 ms* s.Restart(); for (int i = 0; i < 10000000; i++) { result |= (f & TestFlags.Three) != 0; } s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); // *27 ms* Console.ReadLine(); }