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


C# Serializer.ObtainOpenStreamDeserializer方法代码示例

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


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

示例1: ShouldDoBasicOpenStreamSerialization

        public void ShouldDoBasicOpenStreamSerialization(
            [Values(ReferencePreservation.DoNotPreserve, ReferencePreservation.Preserve, ReferencePreservation.UseWeakReference)]
            ReferencePreservation referencePreservation)
        {
            var localSettings = settings.With(referencePreservation: referencePreservation);

            var someObject = Tuple.Create(0, 1);
            var otherObject = Tuple.Create(1, 2);

            var serializer = new Serializer(localSettings);
            var stream = new MemoryStream();
            using(var osSerializer = serializer.ObtainOpenStreamSerializer(stream))
            {
                osSerializer.Serialize(someObject);
                osSerializer.Serialize(someObject);
                osSerializer.Serialize(otherObject);
            }

            stream.Seek(0, SeekOrigin.Begin);

            using(var osDeserializer = serializer.ObtainOpenStreamDeserializer(stream))
            {
                var objs = new object[3];
                for(var i = 0; i < objs.Length; i++)
                {
                    objs[i] = osDeserializer.Deserialize<Tuple<int, int>>();
                }
                Assert.AreEqual(someObject, objs[0]);
                Assert.AreEqual(someObject, objs[1]);
                Assert.AreEqual(otherObject, objs[2]);
            }
        }
开发者ID:StepWoodProductions,项目名称:Migrant,代码行数:32,代码来源:OpenStreamSerializationTests.cs

示例2: ShouldDeserializeMany

        public void ShouldDeserializeMany()
        {
            var serializer = new Serializer(settings.With(useBuffering: false));
            var stream = new MemoryStream();

            var tuples = Enumerable.Range(1, 10).Select(x => Tuple.Create(x, x + 0.5)).ToList();
            using(var osSerializer = serializer.ObtainOpenStreamSerializer(stream))
            {
                foreach(var tuple in tuples)
                {
                    osSerializer.Serialize(tuple);
                }
            }

            stream.Seek(0, SeekOrigin.Begin);

            using(var osDeserializer = serializer.ObtainOpenStreamDeserializer(stream))
            {
                var deserializedTuples = osDeserializer.DeserializeMany<Tuple<int, double>>();
                CollectionAssert.AreEqual(tuples.ToList(), deserializedTuples.ToList());
            }
        }
开发者ID:rogeralsing,项目名称:Migrant,代码行数:22,代码来源:OpenStreamSerializationTests.cs

示例3: ShouldReadPreservationOptionFromTheStream

        public void ShouldReadPreservationOptionFromTheStream(
            [Values(ReferencePreservation.Preserve, ReferencePreservation.DoNotPreserve)]
            ReferencePreservation referencePreservation)
        {
            var localSettings = settings.With(referencePreservation: referencePreservation);
            var oppositeSettings = settings.With(referencePreservation:
                referencePreservation == ReferencePreservation.Preserve
                ? ReferencePreservation.DoNotPreserve : ReferencePreservation.Preserve);

            var someObject = Tuple.Create(0, 1);

            var serializer = new Serializer(localSettings);
            var stream = new MemoryStream();
            using(var osSerializer = serializer.ObtainOpenStreamSerializer(stream))
            {
                osSerializer.Serialize(someObject);
                osSerializer.Serialize(someObject);
            }

            stream.Seek(0, SeekOrigin.Begin);
            serializer = new Serializer(oppositeSettings);

            using(var osDeserializer = serializer.ObtainOpenStreamDeserializer(stream))
            {
                var first = osDeserializer.Deserialize<object>();
                var second = osDeserializer.Deserialize<object>();
                Assert.AreEqual(first, second);
                Assert.AreEqual(first, someObject);
            }
        }
开发者ID:rogeralsing,项目名称:Migrant,代码行数:30,代码来源:OpenStreamSerializationTests.cs

示例4: ShouldntPreserveReferences

        public void ShouldntPreserveReferences()
        {
            var localSettings = settings.With(referencePreservation: ReferencePreservation.DoNotPreserve);

            var someObject = new object();

            var serializer = new Serializer(localSettings);
            var stream = new MemoryStream();
            using(var osSerializer = serializer.ObtainOpenStreamSerializer(stream))
            {
                osSerializer.Serialize(someObject);
                osSerializer.Serialize(someObject);
            }

            stream.Seek(0, SeekOrigin.Begin);

            using(var osDeserializer = serializer.ObtainOpenStreamDeserializer(stream))
            {
                Assert.AreNotSame(osDeserializer.Deserialize<object>(), osDeserializer.Deserialize<object>());
            }
        }
开发者ID:rogeralsing,项目名称:Migrant,代码行数:21,代码来源:OpenStreamSerializationTests.cs


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