コード例 #1
0
        private void UpdateValue(object newValue)
        {
            var  oldValue = value;
            bool changed  = !Equals(oldValue, newValue);

            if (changed && ShouldNotify && !Profile.IsDiscarding)
            {
                using (Profile.TransactionStack.CreateTransaction())
                {
                    Profile.TransactionStack.PushOperation(new SettingsEntryChangeValueOperation(this, oldValue));
                }
                Profile.NotifyEntryChanged(Name);
            }
            value = newValue;
        }
コード例 #2
0
ファイル: SettingsContainer.cs プロジェクト: nikserdev/xenko
        private void ChangeCurrentProfile([NotNull] SettingsProfile oldProfile, [NotNull] SettingsProfile newProfile)
        {
            if (oldProfile == null)
            {
                throw new ArgumentNullException(nameof(oldProfile));
            }
            if (newProfile == null)
            {
                throw new ArgumentNullException(nameof(newProfile));
            }
            currentProfile = newProfile;

            lock (SettingsLock)
            {
                foreach (var key in settingsKeys)
                {
                    object oldValue;
                    oldProfile.GetValue(key.Key, out oldValue, true, false);
                    object newValue;
                    newProfile.GetValue(key.Key, out newValue, true, false);
                    var  oldList       = oldValue as IList;
                    var  newList       = newValue as IList;
                    var  oldDictionary = oldValue as IDictionary;
                    var  newDictionary = newValue as IDictionary;
                    bool isDifferent;
                    if (oldList != null && newList != null)
                    {
                        isDifferent = oldList.Count != newList.Count;
                        for (int i = 0; i < oldList.Count && !isDifferent; ++i)
                        {
                            if (!Equals(oldList[i], newList[i]))
                            {
                                isDifferent = true;
                            }
                        }
                    }
                    else if (oldDictionary != null && newDictionary != null)
                    {
                        isDifferent = oldDictionary.Count != newDictionary.Count;
                        foreach (var k in oldDictionary.Keys)
                        {
                            if (!newDictionary.Contains(k) || !Equals(oldDictionary[k], newDictionary[k]))
                            {
                                isDifferent = true;
                            }
                        }
                    }
                    else
                    {
                        isDifferent = !Equals(oldValue, newValue);
                    }
                    if (isDifferent)
                    {
                        newProfile.NotifyEntryChanged(key.Key);
                    }
                }
            }

            // Changes have been notified, empty the list of modified settings.
            newProfile.ValidateSettingsChanges();
        }