当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadEnum方法代码示例

本文整理汇总了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);
        }
开发者ID:CoreylDagget,项目名称:tesla,代码行数:50,代码来源:EnumDeserializationTest.cs

示例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));
        }
开发者ID:CoreylDagget,项目名称:tesla,代码行数:26,代码来源:EnumDeserializationTest.cs


注:本文中的BinaryReader.ReadEnum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。