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); }
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)); }
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)); }
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; } }
private static IQueryPlanNode DeserializePlan(Type nodeType, BinaryReader reader) { var serializer = new BinarySerializer(); return (IQueryPlanNode) serializer.Deserialize(reader, nodeType); }
private static object ReadObject(BinaryReader reader, Encoding encoding) { var objType = ReadType(reader); var serializer = new BinarySerializer { Encoding = encoding }; return serializer.Deserialize(reader, objType); }
public static ViewInfo Deserialize(Stream stream) { var serializer = new BinarySerializer(); return (ViewInfo) serializer.Deserialize(stream, typeof (ViewInfo)); }
internal static SqlExpression Deserialize(BinaryReader reader) { var serializer = new BinarySerializer(); return (SqlExpression) serializer.Deserialize(reader, typeof(SqlExpression)); }
protected T BinaryDeserialize <T>(Stream stream) where T : class { var serializer = new BinarySerializer(); return((T)serializer.Deserialize(stream)); }
public static ViewInfo FromBinary(ISqlBinary binary) { using (var stream = binary.GetInput()) { var serializer = new BinarySerializer(); return (ViewInfo) serializer.Deserialize(stream); } }
protected T BinaryDeserialize <T>(Stream stream) where T : class { var serializer = new BinarySerializer(); return(serializer.Deserialize(stream, typeof(T)) as T); }