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();
                }
            }
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
 public MessageSerializerService()
 {
     var serializerBuilderResolver = new DebuggingSerializerResolverBuilder<MessageBody>();
     this.messageSerializer = new MessageSerializer(serializerBuilderResolver);
 }
コード例 #4
0
        public MessageSerializerService()
        {
            var serializerBuilderResolver = new DebuggingSerializerResolverBuilder <MessageBody>();

            this.messageSerializer = new MessageSerializer(serializerBuilderResolver);
        }