public string ToJson()
        {
            // 这里忽略_staticObjects这个成员。

            if (_sessionItems == null || _sessionItems.Count == 0)
            {
                return(null);
            }

            Dictionary <string, object> dict = new Dictionary <string, object>(_sessionItems.Count);

            string key;

            NameObjectCollectionBase.KeysCollection keys = _sessionItems.Keys;
            for (int i = 0; i < keys.Count; i++)
            {
                key = keys[i];
                dict.Add(key, _sessionItems[key]);
            }

            SessionStateItem item = new SessionStateItem {
                Dict = dict, Timeout = this._timeout
            };

            return(JsonConvert.SerializeObject(item));
        }
        public static RedisSessionState FromJson(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(null);
            }
            try
            {
                SessionStateItem item = JsonConvert.DeserializeObject <SessionStateItem>(json);

                SessionStateItemCollection collections = new SessionStateItemCollection();

                foreach (KeyValuePair <string, object> kvp in item.Dict)
                {
                    collections[kvp.Key] = kvp.Value;
                }

                return(new RedisSessionState(collections, null, item.Timeout));
            }
            catch
            {
                return(null);
            }
        }
        public string ToJson()
        {
            // 这里忽略_staticObjects这个成员。

            if (_sessionItems == null || _sessionItems.Count == 0)
            {
                return null;
            }

            Dictionary<string, object> dict = new Dictionary<string, object>(_sessionItems.Count);

            string key;
            NameObjectCollectionBase.KeysCollection keys = _sessionItems.Keys;
            for (int i = 0; i < keys.Count; i++)
            {
                key = keys[i];
                dict.Add(key, _sessionItems[key]);
            }

            SessionStateItem item = new SessionStateItem { Dict = dict, Timeout = this._timeout };

            return JsonConvert.SerializeObject(item);
        }