示例#1
0
        public void StreamReadsAndWrites()
        {
            var input = new byte[] { 1, 2, 3, 4, 5 };

            using (var stream = new ValueStream())
            {
                stream.Write(input, 0, input.Length);

                stream.Seek(0);

                var result = new byte[5];
                var read   = stream.Read(result, 0, result.Length);

                Assert.Equal(result.Length, read);
                Assert.Equal(input, result);
            }
        }
示例#2
0
        public void ReadByteWriteByteWorks()
        {
            using (var stream = new ValueStream())
            {
                stream.WriteByte(1);
                stream.WriteByte(2);
                stream.WriteByte(3);
                stream.WriteByte(4);
                stream.WriteByte(5);

                stream.Seek(0);

                Assert.Equal(1, stream.ReadByte());
                Assert.Equal(2, stream.ReadByte());
                Assert.Equal(3, stream.ReadByte());
                Assert.Equal(4, stream.ReadByte());
                Assert.Equal(5, stream.ReadByte());
            }
        }
示例#3
0
        public void DoubleResizing()
        {
            var input = new byte[] { 1, 2, 3, 4, 5 };

            using (var stream = new ValueStream())
            {
                stream.Write(input, 0, input.Length);
                stream.Write(input, 0, input.Length);

                Assert.Equal(10, stream.Position);

                stream.Seek(0);

                var result = new byte[5];
                stream.Read(result, 0, result.Length);
                Assert.Equal(input, result);

                stream.Read(result, 0, result.Length);
                Assert.Equal(input, result);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            Test[] test = new Test[] { new Test3 {
                                           Prop = false, Prop2 = 123
                                       }, new Test2 {
                                           Prop = false, Prop2 = 12
                                       }, new Test3() };

            var config = new SerializerConfig();

            config.Match <Test>();
            config.Match <Test3>();

            var serializer = config.Create();

            using (var stream = new ValueStream())
            {
                serializer.Serialize(stream, test);
                stream.Seek(0);
                var instance = serializer.Deserialize <Test[]>(stream);
            }
        }