Exemple #1
0
        public IDependencyValueStorage this[DependencyValueStorageKey key]
        {
            get
            {
                IDependencyValueStorage storage;
                if (_storages.TryGetValue(key, out storage))
                {
                    return(storage);
                }
                return(null);
            }
            set
            {
                if (key == DefaultKey)
                {
                    throw new InvalidOperationException("Default storage is readonly.");
                }

                IDependencyValueStorage storage;
                if (_storages.TryGetValue(key, out storage))
                {
                    if (storage != value)
                    {
                        storage.CurrentValueChanged -= Storage_CurrentValueChanged;
                        if (value != null)
                        {
                            UpdateStorage(key, storage, value);
                            value.CurrentValueChanged += Storage_CurrentValueChanged;
                        }
                        else
                        {
                            RemoveStorage(key, storage);
                        }
                    }
                }
                else
                {
                    if (value != null)
                    {
                        AddStorage(key, value);
                        value.CurrentValueChanged += Storage_CurrentValueChanged;
                    }
                }
            }
        }
Exemple #2
0
        private void UpdateStorage(DependencyValueStorageKey key, IDependencyValueStorage old, IDependencyValueStorage value)
        {
            var dps = value.Keys.Union(old.Keys).ToList();

            UpdateStorage(dps, () => _storages[key] = value);
        }
Exemple #3
0
        private void RemoveStorage(DependencyValueStorageKey key, IDependencyValueStorage storage)
        {
            var dps = storage.Keys.ToList();

            UpdateStorage(dps, () => _storages.Remove(key));
        }
Exemple #4
0
        private void AddStorage(DependencyValueStorageKey key, IDependencyValueStorage storage)
        {
            var dps = storage.Keys.ToList();

            UpdateStorage(dps, () => _storages.Add(key, storage));
        }