private object SerializeDeserialize(object obj) { MemoryStream memoryStream = null; var serializerResolver = new DebuggingSerializerResolverBuilder <MessageBody>().Build(); var serializer = serializerResolver.GetSerializer(obj.GetType()); try { memoryStream = new MemoryStream(); using (var streamWriter = new StreamWriter(memoryStream)) using (var streamReader = new StreamReader(memoryStream)) { var serializationContext = new SerializationContext(serializerResolver); serializer.Serialize(streamWriter, serializationContext, obj); var arr = memoryStream.ToArray(); Console.WriteLine(BitConverter.ToString(arr)); memoryStream.Position = 0; var deserializationContext = new SerializationContext(serializerResolver); var result = serializer.Deserialize(streamReader, deserializationContext); memoryStream = null; return(result); } } finally { if (memoryStream != null) { memoryStream.Dispose(); } } }
private object SerializeDeserialize(object obj) { MemoryStream memoryStream = null; var serializerResolver = new DebuggingSerializerResolverBuilder<MessageBody>().Build(); var serializer = serializerResolver.GetSerializer(obj.GetType()); try { memoryStream = new MemoryStream(); using (var streamWriter = new StreamWriter(memoryStream)) using (var streamReader = new StreamReader(memoryStream)) { var serializationContext = new SerializationContext(serializerResolver); serializer.Serialize(streamWriter, serializationContext, obj); var arr = memoryStream.ToArray(); Console.WriteLine(BitConverter.ToString(arr)); memoryStream.Position = 0; var deserializationContext = new SerializationContext(serializerResolver); var result = serializer.Deserialize(streamReader, deserializationContext); memoryStream = null; return result; } } finally { if (memoryStream != null) { memoryStream.Dispose(); } } }
public MessageSerializerService() { var serializerBuilderResolver = new DebuggingSerializerResolverBuilder<MessageBody>(); this.messageSerializer = new MessageSerializer(serializerBuilderResolver); }
public MessageSerializerService() { var serializerBuilderResolver = new DebuggingSerializerResolverBuilder <MessageBody>(); this.messageSerializer = new MessageSerializer(serializerBuilderResolver); }