Beispiel #1
0
 public static void Remove <K>(this StorageSet set, K key)
 {
     if (set.Contains(key))
     {
         set.Context.Delete(ElementKey(set.BaseKey, key));
         var size = set.Count() - 1;
         set.Context.Put(CountKey(set.BaseKey), size);
     }
 }
Beispiel #2
0
        public static void Add <K>(this StorageSet set, K key)
        {
            bool exists = set.Contains(key);

            if (!exists)
            {
                set.Context.Put(ElementKey(set.BaseKey, key), new byte[] { 1 });

                var size = set.Count() + 1;
                set.Context.Put(CountKey(set.BaseKey), size);
            }
        }
Beispiel #3
0
        public static V[] AllValues <V>(this StorageSet set)
        {
            var values      = new List <V>();
            var countKey    = CountKey(set.BaseKey);
            var found       = false;
            var countKeyRun = false;

            set.Context.Visit((key, value) =>
            {
                if (!found && key.SequenceEqual(countKey))
                {
                    countKeyRun = true;
                    found       = true;
                }

                if (!countKeyRun)
                {
                    V Val;
                    if (typeof(IStorageCollection).IsAssignableFrom(typeof(V)))
                    {
                        var args = new object[] { value, set.Context };
                        var obj  = (V)Activator.CreateInstance(typeof(V), args);
                        Val      = obj;
                        values.Add(Val);
                    }
                    else
                    {
                        Val = Serialization.Unserialize <V>(value);
                        values.Add(Val);
                    }
                }
                else
                {
                    countKeyRun = false;
                }
            }, (uint)set.Count(), set.BaseKey);

            return(values.ToArray());
        }