Ejemplo n.º 1
0
        private static void PersistDictionaryImpl <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, uint count, PersistDictionaryItemCallback <TKey, TValue> callback)
        {
            persister.BeginArray("Items");

            if (persister.Mode == StatePersistMode.Read)
            {
                value.Clear();

                for (var i = 0; i < count; i++)
                {
                    persister.BeginObject();

                    var itemKey   = default(TKey);
                    var itemValue = default(TValue);
                    callback(persister, ref itemKey, ref itemValue);
                    value.Add(itemKey, itemValue);

                    persister.EndObject();
                }
            }
            else
            {
                foreach (var item in value)
                {
                    persister.BeginObject();

                    var itemKey   = item.Key;
                    var itemValue = item.Value;
                    callback(persister, ref itemKey, ref itemValue);

                    persister.EndObject();
                }
            }

            persister.EndArray();
        }
Ejemplo n.º 2
0
        public static void PersistDictionaryWithUInt32Count <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var count = (uint)value.Count;

            persister.PersistUInt32(ref count);

            persister.PersistDictionaryImpl(value, count, callback);

            persister.EndObject();
        }
Ejemplo n.º 3
0
        public static void PersistDictionaryValue <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback)
        {
            persister.BeginObject();

            var count = (ushort)value.Count;

            persister.PersistUInt16(ref count);

            persister.PersistDictionaryImpl(value, count, callback);

            persister.EndObject();
        }