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


C# Unpacker.Unpack方法代码示例

本文整理汇总了C#中Unpacker.Unpack方法的典型用法代码示例。如果您正苦于以下问题:C# Unpacker.Unpack方法的具体用法?C# Unpacker.Unpack怎么用?C# Unpacker.Unpack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unpacker的用法示例。


在下文中一共展示了Unpacker.Unpack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSimplePropertyPackUnpack

        public void TestSimplePropertyPackUnpack()
        {
            using (IBuffer buffer = new SimpleBuffer())
            {
                RawDataSerializer ms = new RawDataSerializer(buffer);
                BinaryPackager packer = new BinaryPackager();

                RegisteredPackageDefinition registeredPackageDefinition;
                packer.RegisterDefinition(new PackageDefinition<PackData>()
                                                        .Define(x => x.IntData, x => x.IntData)
                                                        .Define(x => x.StringData, x => x.StringData)
                                                        .Define(x => x.DateTimeData, x => x.DateTimeData), out registeredPackageDefinition);
                var packData = new PackData()
                {
                    ArrayPackData = null,
                    DateTimeData = DateTime.Now,
                    IntData = 124,
                    StringData = "Some String",
                };

                packer.Pack(packData, ms);

                using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
                {
                    Unpacker unpacker = new Unpacker();
                    unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>()
                    {
                        DefinitionId = registeredPackageDefinition.DefinitionId
                    }
                                                      .DefineInt("IntData", (data, i) => data.IntData = i)
                                                      .DefineString("StringData", (data, s) => data.StringData = s)
                                                      .DefineDateTime("DateTimeData",
                                                                      (data, time) => data.DateTimeData = time));

                    var unpackData = unpacker.Unpack<PackData>(deserilizer);
                    Assert.IsNotNull(unpackData);
                    CheckValidPackData(packData, unpackData);
                    Assert.AreEqual(packData.ArrayPackData, unpackData.ArrayPackData);
                }
            }
        }
开发者ID:ronenbarak,项目名称:Whitelog,代码行数:41,代码来源:ListWritersTester.cs

示例2: TestArrayWithSimplePropertyPackUnpack

        public void TestArrayWithSimplePropertyPackUnpack()
        {
            using (IBuffer buffer = new SimpleBuffer())
            {
                RawDataSerializer ms = new RawDataSerializer(buffer);
                BinaryPackager packer = new BinaryPackager();

                RegisteredPackageDefinition registeredPackageDefinition;
                packer.RegisterDefinition(new PackageDefinition<PackData>()
                                                        .Define(x => x.IntData, x => x.IntData)
                                                        .Define(x => x.StringData, x => x.StringData)
                                                        .Define(x => x.ArrayPackData, x => x.ArrayPackData)
                                                        .Define(x => x.DateTimeData, x => x.DateTimeData), out registeredPackageDefinition);
                var packData = new PackData()
                {
                    ArrayPackData = new List<PackData>()
                                        {
                                            new PackData()
                                            {
                                                IntData =1,
                                                StringData = "First String",
                                            },
                                            new PackData()
                                            {
                                                IntData =2,
                                                DateTimeData = DateTime.Now + TimeSpan.FromHours(2),
                                                ArrayPackData =  new List<PackData>(),
                                            },
                                            new PackData()
                                            {
                                                StringData = string.Empty
                                            },
                                        },
                    DateTimeData = DateTime.Now,
                    IntData = 124,
                    StringData = "Some String",
                };

                packer.Pack(packData, ms);

                using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
                {

                    Unpacker unpacker = new Unpacker();
                    unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>()
                    {
                        DefinitionId = registeredPackageDefinition.DefinitionId
                    }
                                                      .DefineInt("IntData", (data, i) => data.IntData = i)
                                                      .DefineString("StringData", (data, s) => data.StringData = s)
                                                      .DefineEnumerable("ArrayPackData",
                                                                        (data, enumerable) => data.ArrayPackData = enumerable.NullGurd(x => x.OfType<PackData>().ToList()))
                                                      .DefineDateTime("DateTimeData", (data, time) => data.DateTimeData = time));

                    var unpackData = unpacker.Unpack<PackData>(deserilizer);
                    Assert.IsNotNull(unpackData);
                    CheckValidPackData(unpackData, packData);
                    Assert.IsNotNull(packData.ArrayPackData);

                    Assert.AreEqual(3, packData.ArrayPackData.Count);

                    CheckValidPackData(packData.ArrayPackData[0], unpackData.ArrayPackData[0]);
                    Assert.IsNull(unpackData.ArrayPackData[0].ArrayPackData);

                    CheckValidPackData(packData.ArrayPackData[1], unpackData.ArrayPackData[1]);
                    Assert.IsNotNull(unpackData.ArrayPackData[1].ArrayPackData);
                    Assert.AreEqual(0, unpackData.ArrayPackData[1].ArrayPackData.Count);

                    CheckValidPackData(packData.ArrayPackData[2], unpackData.ArrayPackData[2]);
                    Assert.IsNull(unpackData.ArrayPackData[2].ArrayPackData);
                }
            }
        }
开发者ID:ronenbarak,项目名称:Whitelog,代码行数:73,代码来源:ListWritersTester.cs

示例3: TestInstanceCreatorPackUnpack

        public void TestInstanceCreatorPackUnpack()
        {
            using (IBuffer buffer = new SimpleBuffer())
            {
                RawDataSerializer ms = new RawDataSerializer(buffer);
                BinaryPackager packer = new BinaryPackager();

                RegisteredPackageDefinition registeredPackageDefinition;
                packer.RegisterDefinition(new PackageDefinition<PackData>(), out registeredPackageDefinition);

                packer.Pack(new PackData(), ms);

                using (StreamDeserilizer deserilizer = new StreamDeserilizer(buffer.Buffer))
                {
                    Unpacker unpacker = new Unpacker();
                    unpacker.AddPackageDefinition(new EmptyConstractorUnpackageDefinition<PackData>() { DefinitionId = registeredPackageDefinition.DefinitionId });

                    Assert.IsNotNull(unpacker.Unpack<PackData>(deserilizer));
                }
            }
        }
开发者ID:ronenbarak,项目名称:Whitelog,代码行数:21,代码来源:ListWritersTester.cs


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