示例#1
0
        public byte[] Serialize(object data)
        {
            if (data == null)
            {
                data = new RedisNull();
            }

            SessionObject sessionObject = new SessionObject();

            sessionObject.Type = data.GetType();
            sessionObject.Data = JsonConvert.SerializeObject(data, serializerSettings);
            return(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(sessionObject)));
        }
示例#2
0
        public object Deserialize(byte[] data)
        {
            if (data == null)
            {
                return(null);
            }
            SessionObject sessionObject = ( SessionObject )JsonConvert.DeserializeObject(Encoding.ASCII.GetString(data, 0, data.Length), typeof(SessionObject));
            object        retObject     = ( object )JsonConvert.DeserializeObject(sessionObject.Data, sessionObject.Type, serializerSettings);

            if (retObject.GetType() == typeof(RedisNull))
            {
                return(null);
            }
            return(retObject);
        }