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()); } }
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); } }
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)); } }