Beispiel #1
0
 public static T TryGetFromViewState <T>(StateBag alternate, string key, T value)
 {
     if (Equals(value, default(T)))
     {
         if (alternate[key] != null)
         {
             value = (T)SPSSerialization.Deserialize((string)alternate[key]);
         }
     }
     return(value);
 }
Beispiel #2
0
        public static T TryGetFromSessionState <T>(Page page, StateBag alternate, string key, T value)
        {
            if (Equals(value, default(T)))
            {
                if (page.Session.Mode != SessionStateMode.Off)
                {
                    if (page.Session[key] != null)
                    {
                        value = (T)SPSSerialization.Deserialize((string)page.Session[key]);
                    }
                }
                else
                {
                    value = TryGetFromViewState(alternate, key, value);
                }
            }

            return(value);
        }
Beispiel #3
0
        public void SerializeDeserialize()
        {
            Dictionary <string, int> beforeDictionary = new Dictionary <string, int>();

            beforeDictionary.Add("Key1", 10);
            beforeDictionary.Add("Key2", 20);

            string serialized = SPSSerialization.Serialize(beforeDictionary);

            Dictionary <string, int> afterDictionary = (Dictionary <string, int>)SPSSerialization.Deserialize(serialized);

            Assert.IsTrue(beforeDictionary.Count == afterDictionary.Count);

            Assert.IsTrue(afterDictionary.ContainsKey("Key1"));
            Assert.IsTrue(afterDictionary.ContainsKey("Key2"));

            Assert.IsTrue(afterDictionary["Key1"] == 10);
            Assert.IsTrue(afterDictionary["Key2"] == 20);
        }