public void TestNonSerializableMemberInitialization()
        {
            storage.Put("test", new ClassWithNonSerializableMembers {
                TestInteger = 2
            });

            var restored = storage.Get <ClassWithNonSerializableMembers>("test");

            Assert.AreEqual(1, restored.TestInteger);

            Assert.DoesNotThrow(restored.ExecuteTestAction);
        }
        public PersistentList(string editGroup, Func <T, string> serialize = null, Func <string, T> deserialize = null)
        {
            try {
                storage = SimpleStorage.EditGroup(editGroup);
                ids     = storage.Get <List <string> >(idListKey) ?? new List <string>();

                var broken = new List <string>();
                foreach (var i in ids)
                {
                    T item = default(T);
                    try {
                        item = deserialize == null?storage.Get <T>(i) : deserialize(storage.Get(i));
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }

                    if (item == null)
                    {
                        broken.Add(i);
                        continue;
                    }
                    items.Add(item);
                }

                if (broken.Count > 0)
                {
                    foreach (var id in broken)
                    {
                        storage.Delete(id);
                        ids.Remove(id);
                        storage.Put(idListKey, ids);
                    }
                }

                CustomSerializer = serialize;
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
 public void TestSavingString()
 {
     storage.Put("test", "hello world");
     Assert.AreEqual("hello world", storage.Get("test"));
 }
Beispiel #4
0
 public PersistentStrings(string groupName)
 {
     storage = SimpleStorage.EditGroup(groupName);
     list    = storage.Get <List <string> >(key) ?? new List <string>();
 }