public byte[] Serialize(object data)
        {
            if (data == null)
            {
                data = new RedisNull();
            }
            var binaryFormatter = new BinaryFormatter();

            using (var memoryStream = new MemoryStream())
            {
                binaryFormatter.Serialize(memoryStream, data);
                byte[] objectDataAsStream = memoryStream.ToArray();
                return(objectDataAsStream);
            }
        }
        internal static byte[] GetBytesFromObject(object data)
        {
            if (data == null)
            {
                data = new RedisNull();
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (MemoryStream memoryStream = new MemoryStream())
            {
                binaryFormatter.Serialize(memoryStream, data);
                byte[] objectDataAsStream = memoryStream.ToArray();
                return objectDataAsStream;
            }
        }
示例#3
0
        internal static byte[] GetBytesFromObject(object data)
        {
            if (data == null)
            {
                data = new RedisNull();
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                binaryFormatter.Serialize(memoryStream, data);
                byte[] objectDataAsStream = memoryStream.ToArray();
                return(objectDataAsStream);
            }
        }
        internal static byte[] GetBytesFromObject(object data)
        {
            if (data == null)
            {
                data = new RedisNull();
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (MemoryStream memoryStream = new MemoryStream())
            using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress))
            {
                binaryFormatter.Serialize(deflateStream, data);
                deflateStream.Close();
                byte[] objectDataAsStream = memoryStream.ToArray();
                return objectDataAsStream;
            }
        }