Exemplo n.º 1
0
            public static byte[] Serialize(Type type, object objectToSerialize, bool preserveTypeInfo = false, bool compress = true)
            {
                var s = new Wr.Serializer(new Wr.SerializerOptions(preserveObjectReferences: preserveTypeInfo));

                using (var ms = new MemoryStream())
                {
                    s.Serialize(objectToSerialize, ms);
                    return(ms.ToArray());
                }
            }
Exemplo n.º 2
0
 public static object Deserialize(Type type, byte[] data, bool suppressErrors = true)
 {
     try
     {
         var s = new Wr.Serializer(new Wr.SerializerOptions());
         using (var ms = new MemoryStream(data))
         {
             return(s.Deserialize(ms));
         }
     }
     catch (Exception e)
     {
         if (!suppressErrors)
         {
             ExceptionDispatchInfo.Capture(e).Throw();
         }
         return(null);
     }
 }
Exemplo n.º 3
0
 public static T Deserialize <T>(byte[] data, bool suppressErrors = true)
 {
     try
     {
         var s = new Wr.Serializer(new Wr.SerializerOptions());
         using (var ms = new MemoryStream(data))
         {
             return(s.Deserialize <T>(ms));
         }
     }
     catch (Exception e)
     {
         if (!suppressErrors)
         {
             ExceptionDispatchInfo.Capture(e).Throw();
         }
         return(default(T));
     }
 }