Пример #1
0
        private T SerializerLoop <T>(T input)
        {
            var serializer = new ILBasedSerializer(new CachedTypeResolver());

            Assert.True(serializer.IsSupportedType(input.GetType()));

            var serializationContext =
                new SerializationContext(this.fixture.SerializationManager)
            {
                StreamWriter = new BinaryTokenStreamWriter()
            };

            serializer.Serialize(input, serializationContext, typeof(T));
            var deserializationContext = new DeserializationContext(this.fixture.SerializationManager)
            {
                StreamReader = new BinaryTokenStreamReader(serializationContext.StreamWriter.ToBytes())
            };

            return((T)serializer.Deserialize(typeof(T), deserializationContext));
        }
Пример #2
0
        private T SerializerLoop <T>(T input)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var serializer = new ILBasedSerializer(new CachedTypeResolver());
#pragma warning restore CS0618 // Type or member is obsolete
            Assert.True(serializer.IsSupportedType(input.GetType()));

            var writer = new BinaryTokenStreamWriter();
            var serializationContext =
                new SerializationContext(this.fixture.SerializationManager)
            {
                StreamWriter = writer
            };
            serializer.Serialize(input, serializationContext, typeof(T));
            var deserializationContext = new DeserializationContext(this.fixture.SerializationManager)
            {
                StreamReader = new BinaryTokenStreamReader(writer.ToBytes())
            };

            return((T)serializer.Deserialize(typeof(T), deserializationContext));
        }