private TestEnum FromInteger(ulong integerValue) { Contract.Assume(Enum.IsDefined(typeof(TestEnum), (int)integerValue)); TestEnum value; bool found = EnumTraits <TestEnum> .TryConvert(integerValue, out value); XAssert.IsTrue(found, "Failed to find a value"); return(value); }
public void CanConvertFromInteger() { XAssert.AreEqual(TestEnum.A, FromInteger((ulong)TestEnum.A)); XAssert.AreEqual(TestEnum.B, FromInteger((ulong)TestEnum.B)); XAssert.AreEqual(TestEnum.C, FromInteger((ulong)TestEnum.C)); TestEnum notFound; EnumTraits <TestEnum> .TryConvert(123, out notFound); XAssert.AreEqual(default(TestEnum), notFound); }
public static ReadUsnJournalStatus ReadUsnJournalReadStatus(this ChangeJournalServiceProtocolReader reader) { Contract.Requires(reader != null); var readStatusValue = reader.ReadByte(); ReadUsnJournalStatus readStatus; if (!EnumTraits <ReadUsnJournalStatus> .TryConvert(readStatusValue, out readStatus)) { throw new BuildXLException("Invalid ReadUsnJournalStatus"); } return(readStatus); }
public static QueryUsnJournalResult ReadQueryUsnJournalResult(this ChangeJournalServiceProtocolReader reader) { Contract.Requires(reader != null); var queryStatusValue = reader.ReadInt32(); QueryUsnJournalStatus queryStatus; if (!EnumTraits <QueryUsnJournalStatus> .TryConvert(queryStatusValue, out queryStatus)) { throw new BuildXLException("Invalid QueryUsnJournalStatus"); } if (queryStatus == QueryUsnJournalStatus.Success) { QueryUsnJournalData data = reader.ReadUsnJournalData(); return(new QueryUsnJournalResult(queryStatus, data)); } return(new QueryUsnJournalResult(queryStatus, data: null)); }