public bool RunTest() { bool success = true; { TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>(); Debug.Assert(flags.IsEmpty()); success &= flags.IsEmpty(); for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex) { Debug.Assert(!flags.Test(bitIndex)); success &= !flags.Test(bitIndex); flags.Set(bitIndex, true); Debug.Assert(flags.Test(bitIndex)); success &= flags.Test(bitIndex); flags.Set(bitIndex, false); Debug.Assert(!flags.Test(bitIndex)); success &= !flags.Test(bitIndex); } } { TypedFlags <TestEnum> flagsA = new TypedFlags <TestEnum>(); TypedFlags <TestEnum> flagsB = new TypedFlags <TestEnum>(); flagsB.Set(TestEnum._flag10, true); TypedFlags <TestEnum> flagsC = new TypedFlags <TestEnum>(flagsB); Debug.Assert(flagsA != flagsB); success &= flagsA != flagsB; Debug.Assert(flagsB == flagsC); success &= flagsB == flagsC; } { TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>( TypedFlags <TestEnum> .FLAG(TestEnum._flag4) | TypedFlags <TestEnum> .FLAG(TestEnum._flag9)); for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex) { if (bitIndex == TestEnum._flag4 || bitIndex == TestEnum._flag9) { Debug.Assert(flags.Test(bitIndex)); success &= flags.Test(bitIndex); } else { Debug.Assert(!flags.Test(bitIndex)); success &= !flags.Test(bitIndex); } } } return(success); }