private object ObjectDeserializer(byte[] bytes, Type type)
 {
     using (var ms = new MemoryStream(bytes))
     {
         var res = _serializer.Deserialize <object>(ms);
         return(res);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Deserializes a byte array into an object of type <paramref name="type" />.
 /// </summary>
 /// <param name="bytes">The array containing the serialized object</param>
 /// <param name="type">The type of object contained in the array</param>
 /// <returns>The object contained in the array</returns>
 public override object FromBinary(byte[] bytes, Type type)
 {
     using (var ms = new MemoryStream(bytes))
     {
         var res = _serializer.Deserialize <object>(ms);
         return(res);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deserializes a byte array into an object of type <paramref name="type" />.
 /// </summary>
 /// <param name="bytes">The array containing the serialized object</param>
 /// <param name="type">The type of object contained in the array</param>
 /// <returns>The object contained in the array</returns>
 public override object FromBinary(byte[] bytes, Type type)
 {
     try
     {
         using (var ms = new MemoryStream(bytes))
         {
             var res = _serializer.Deserialize <object>(ms);
             return(res);
         }
     }
     catch (Exception ex)
     {
         throw new SerializationException($"Failed to deserialize instance of type {type}. {ex.Message}", ex);
     }
 }
Exemplo n.º 4
0
        /// <inheritdoc />
        public sealed override object DeepCopyObject(object source)
        {
            if (source == null)
            {
                return(null);
            }

            var type = source.GetType();

            using (var ms = MemoryStreamManager.GetStream())
            {
                _copier.Serialize(source, ms);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                return(_copier.Deserialize(ms));
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public sealed override T ReadFromStream <T>(Stream readStream, Encoding effectiveEncoding)
        {
            if (null == readStream)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.readStream);
            }

            // 不是 Stream 都会实现 Position、Length 这两个属性
            //if (readStream.Position == readStream.Length) { return GetDefaultValueForType(type); }

            try
            {
                return((T)_serializer.Deserialize(readStream));
            }
            catch (Exception ex)
            {
                s_logger.LogError(ex.ToString());
                return(default);
Exemplo n.º 6
0
 /// <summary>
 /// Deserializes a byte array into an object of type <paramref name="type" />.
 /// </summary>
 /// <param name="bytes">The array containing the serialized object</param>
 /// <param name="type">The type of object contained in the array</param>
 /// <returns>The object contained in the array</returns>
 public override object FromBinary(byte[] bytes, Type type)
 {
     try
     {
         using (var ms = new MemoryStream(bytes))
         {
             var res = _serializer.Deserialize<object>(ms);
             return res;
         }
     }
     catch (TypeLoadException e)
     {
         throw new SerializationException(e.Message, e);
     }
     catch(NotSupportedException e)
     {
         throw new SerializationException(e.Message, e);
     }
     catch (ArgumentException e)
     {
         throw new SerializationException(e.Message, e);
     }
 }
Exemplo n.º 7
0
 public int Hyperion()
 {
     HyperionInput.Position = 0;
     return(SumResult(HyperionSerializer.Deserialize <IntClass>(HyperionInput)));
 }
Exemplo n.º 8
0
 public int Hyperion()
 {
     HyperionObj.Position = 0;
     return(SumResult(HyperionSerializer.Deserialize <IntStruct>(HyperionObj)));
 }
Exemplo n.º 9
0
 public int Hyperion()
 {
     HyperionObj.Position = 0;
     return(SumResult(HyperionSerializer.Deserialize <MsgPackInts>(HyperionObj)));
 }