Example #1
0
        public static bool CanSerializeBytes <T>(this IByteSerializer serializer, T item)
        {
            var text = serializer.SerializeToBytes(item);

            var obj = serializer.Deserialize <T>(text);

            return(obj.Equals(item));
        }
Example #2
0
        public static IBlobSerializer AsBlobSerializer(this IByteSerializer serializer)
        {
            var gm = typeof(IByteSerializer).GetTypeInfo().GetDeclaredMethod("Deserialize");

            return(new BlobSerializerDelegate(
                       obj => serializer.SerializeToBytes(obj),
                       (data, type) => gm.MakeGenericMethod(type).Invoke(serializer, new[] { data }),
                       serializer.CanDeserialize));
        }
 /// <summary>
 /// Gets bytes from the object.
 /// </summary>
 /// <typeparam name="T">Type of object.</typeparam>
 /// <param name="obj">Object to turn into bytes.</param>
 /// <returns>Byte array.</returns>
 protected virtual byte[] GetBytes <T>(T obj)
 {
     return(_serializer.SerializeToBytes(obj));
 }