Пример #1
0
 public static T DeserializeFromBytes <T>(this IStreamSerializer serializer, byte[] data)
 {
     using (var stream = new MemoryStream(data))
     {
         return(serializer.Deserialize <T>(stream));
     }
 }
Пример #2
0
 /// <summary>
 /// Deserializes from bytes.
 /// </summary>
 /// <param name="serializer">The serializer.</param>
 /// <param name="data">The data.</param>
 /// <param name="type">The type.</param>
 /// <returns>System.Object.</returns>
 public static object DeserializeFromBytes(this IStreamSerializer serializer, byte[] data, Type type)
 {
     using (var stream = new MemoryStream(data))
     {
         return(serializer.Deserialize(stream, type));
     }
 }
 public static T Deserialize <T>(string filePath, IStreamSerializer <T> streamSerializer)
 {
     using (var fileStream = FileStreamHelper.NewRead(filePath))
     {
         var value = streamSerializer.Deserialize(fileStream);
         return(value);
     }
 }
Пример #4
0
        /// <summary>
        /// Deserializes from string.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="value">The value.</param>
        /// <param name="type">The type.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns>System.Object.</returns>
        public static object DeserializeFromString(this IStreamSerializer serializer, string value, Type type, Encoding encoding = null)
        {
            var bytes = encoding == null?Convert.FromBase64String(value) : encoding.GetBytes(value);

            using (var stream = new MemoryStream(bytes))
            {
                return(serializer.Deserialize(stream, type));
            }
        }
Пример #5
0
        public static T DeserializeFromString <T>(this IStreamSerializer serializer, string value, Encoding encoding = null)
        {
            //var encoder = encoding ?? Encoding.UTF8;

            //var bytes = encoder.GetBytes(value);
            var bytes = Convert.FromBase64String(value);

            using (var stream = new MemoryStream(bytes))
            {
                return(serializer.Deserialize <T>(stream));
            }
        }
Пример #6
0
        public static bool CanSerializeStream <T>(this IStreamSerializer serializer, T item)
        {
            var encoder = Encoding.UTF8;

            using (var stream = new StreamReader(new MemoryStream(), encoder))
            {
                serializer.Serialize <T>(item, stream.BaseStream);
                stream.BaseStream.Position = 0;
                var obj = serializer.Deserialize <T>(stream.BaseStream);
                return(obj.Equals(item));
            }
        }
Пример #7
0
        public bool Contains(KeyValuePair <TKey, TValue> item)
        {
            var stream = _hash.Get(item.Key);

            return(stream != null && item.Value.Equals(_valueSerializer.Deserialize(stream)));
        }