Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
 public void TestSavingString()
 {
     storage.Put("test", "hello world");
     Assert.AreEqual("hello world", storage.Get("test"));
 }
Пример #4
0
 public PersistentStrings(string groupName)
 {
     storage = SimpleStorage.EditGroup(groupName);
     list    = storage.Get <List <string> >(key) ?? new List <string>();
 }