本文整理汇总了C#中BinaryReader.ReadEnum方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadEnum方法的具体用法?C# BinaryReader.ReadEnum怎么用?C# BinaryReader.ReadEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadEnum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicReadEnumTest
public void BasicReadEnumTest()
{
// Test Enum Test value Encoded As Encoded Bytes
// TestStatus.Late 1 2 00000010
// TestStatus.OnTime 2 4 00000100
// TestStatus.early 3 6 00000110
// TestEquality.LessThan -1 1 00000001
// TestEquality.EqualTo 0 0 00000000
// TestEquality.GreaterThan 1 2 00000010
byte[] buffer =
{
0x02,
0x04,
0x06,
0x01,
0x00,
0x02
};
BinaryReader reader = new BinaryReader(buffer, DeserializationHelper.CannedVersion);
string name = string.Empty;
TestStatus actual;
TestStatus expected = TestStatus.Late;
actual = reader.ReadEnum<TestStatus>(name);
Assert.AreEqual(expected, actual);
expected = TestStatus.OnTime;
actual = reader.ReadEnum<TestStatus>(name);
Assert.AreEqual(expected, actual);
expected = TestStatus.Early;
actual = reader.ReadEnum<TestStatus>(name);
Assert.AreEqual(expected, actual);
TestEquality actual1;
TestEquality expected1 = TestEquality.LessThan;
actual1 = reader.ReadEnum<TestEquality>(name);
Assert.AreEqual(expected1, actual1);
expected1 = TestEquality.EqualTo;
actual1 = reader.ReadEnum<TestEquality>(name);
Assert.AreEqual(expected1, actual1);
expected1 = TestEquality.GreaterThan;
actual1 = reader.ReadEnum<TestEquality>(name);
Assert.AreEqual(expected1, actual1);
}
示例2: ReadOutofBoundsEnumTest
public void ReadOutofBoundsEnumTest()
{
// Test Enum Test value Encoded As Encoded Bytes
// Invalid value 4 8 00001000
byte[] buffer =
{
0x08
};
//Write an invalid value
BinaryReader reader = new BinaryReader(buffer, DeserializationHelper.CannedVersion);
string name = string.Empty;
Exception expectedExcetpion = null;
TestStatus actual;
try
{
actual = reader.ReadEnum<TestStatus>(name);
}
catch (Exception ex)
{
expectedExcetpion = ex;
}
Assert.IsNotNull(expectedExcetpion);
Assert.IsInstanceOfType(expectedExcetpion, typeof(TeslaDeserializationException));
}