Deserialize() public method

public Deserialize ( BinaryReader reader ) : object
reader System.IO.BinaryReader
return object
        public static void SerializeObjectNameWithNoParent()
        {
            var objName = new ObjectName("name");

            var serializer = new BinarySerializer();
            byte[] bytes;

            using (var memoryStream = new MemoryStream()) {
                serializer.Serialize(memoryStream, objName);
                memoryStream.Flush();
                bytes = memoryStream.ToArray();
            }

            object graph = null;
            using (var memoryStream = new MemoryStream(bytes)) {
                graph = serializer.Deserialize(memoryStream, typeof(ObjectName));
            }

            Assert.IsNotNull(graph);
            Assert.IsInstanceOf<ObjectName>(graph);

            var objName2 = (ObjectName) graph;
            Assert.AreEqual(objName.Name, objName2.Name);
            Assert.AreEqual(objName, objName2);
        }
        public static void SerializeImplicit()
        {
            var obj = new TestClass2("test2");

            var serializer = new BinarySerializer();
            byte[] bytes;

            using (var memoryStream = new MemoryStream()) {
                serializer.Serialize(memoryStream, obj);
                memoryStream.Flush();
                bytes = memoryStream.ToArray();
            }

            object graph = null;
            using (var memoryStream = new MemoryStream(bytes)) {
                graph = serializer.Deserialize(memoryStream, typeof(TestClass2));
            }

            Assert.IsNotNull(graph);
            Assert.IsInstanceOf<TestClass2>(obj);

            obj = (TestClass2) graph;
            Assert.AreEqual("test2", obj.Value);
            Assert.IsNull(obj.Parent);
        }
Exemplo n.º 3
0
        public static T Serialize <T>(T obj)
        {
            var serializer = new BinarySerializer();
            var stream     = new MemoryStream();

            serializer.Serialize(obj, stream);

            stream.Seek(0, SeekOrigin.Begin);

            return((T)serializer.Deserialize(typeof(T), stream));
        }
        private static object Serialize(object value)
        {
            var stream     = new MemoryStream();
            var serializer = new BinarySerializer();

            serializer.Serialize(value, stream);

            stream.Seek(0, SeekOrigin.Begin);

            return(serializer.Deserialize(value.GetType(), stream));
        }
Exemplo n.º 5
0
        public static void Serialize()
        {
            var obj = Type.NewObject(SqlExpression.Constant(34));

            var serializer = new BinarySerializer();
            var stream = new MemoryStream();
            serializer.Serialize(stream, obj);

            stream.Flush();

            stream.Seek(0, SeekOrigin.Begin);

            var serialized = (SqlUserObject) serializer.Deserialize(stream);

            Assert.IsNotNull(serialized);
            Assert.IsTrue(obj.Equals(serialized));
        }
Exemplo n.º 6
0
 private static InvokeArgument[] DeserializeArguments(byte[] bytes)
 {
     using (var stream = new MemoryStream(bytes)) {
         var serializer = new BinarySerializer();
         var args = (TriggerArgument) serializer.Deserialize(stream);
         return args.Arguments;
     }
 }
Exemplo n.º 7
0
 private static IQueryPlanNode DeserializePlan(Type nodeType, BinaryReader reader)
 {
     var serializer = new BinarySerializer();
     return (IQueryPlanNode) serializer.Deserialize(reader, nodeType);
 }
Exemplo n.º 8
0
        private static object ReadObject(BinaryReader reader, Encoding encoding)
        {
            var objType = ReadType(reader);
            var serializer = new BinarySerializer {
                Encoding = encoding
            };

            return serializer.Deserialize(reader, objType);
        }
Exemplo n.º 9
0
 public static ViewInfo Deserialize(Stream stream)
 {
     var serializer = new BinarySerializer();
     return (ViewInfo) serializer.Deserialize(stream, typeof (ViewInfo));
 }
Exemplo n.º 10
0
 internal static SqlExpression Deserialize(BinaryReader reader)
 {
     var serializer = new BinarySerializer();
     return (SqlExpression) serializer.Deserialize(reader, typeof(SqlExpression));
 }
Exemplo n.º 11
0
        protected T BinaryDeserialize <T>(Stream stream) where T : class
        {
            var serializer = new BinarySerializer();

            return((T)serializer.Deserialize(stream));
        }
Exemplo n.º 12
0
 public static ViewInfo FromBinary(ISqlBinary binary)
 {
     using (var stream = binary.GetInput()) {
         var serializer = new BinarySerializer();
         return (ViewInfo) serializer.Deserialize(stream);
     }
 }
Exemplo n.º 13
0
        protected T BinaryDeserialize <T>(Stream stream) where T : class
        {
            var serializer = new BinarySerializer();

            return(serializer.Deserialize(stream, typeof(T)) as T);
        }