private IEnumerable <SettingProperty> ChangedProperties(SettingObject newSettings)
        {
            PValueEqualityComparer eq = PValueEqualityComparer.Instance;

            foreach (var property in Settings.Schema.AllProperties)
            {
                // Change if added, updated or deleted.
                if (Settings.TryGetRawValue(property, out PValue oldValue))
                {
                    if (newSettings.TryGetRawValue(property, out PValue newValue))
                    {
                        if (!eq.AreEqual(oldValue, newValue))
                        {
                            // Updated.
                            yield return(property);
                        }
                    }
                    else
                    {
                        // Deleted.
                        yield return(property);
                    }
                }
                else if (newSettings.TryGetRawValue(property, out _))
                {
                    // Added.
                    yield return(property);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Compares this <see cref="PMap"/> with another and returns if they are equal.
        /// </summary>
        /// <param name="other">
        /// The <see cref="PMap"/> to compare with.
        /// </param>
        /// <returns>
        /// true if both <see cref="PMap"/> instances are equal; otherwise false.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="other"/> is null.
        /// </exception>
        public bool EqualTo(PMap other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            // Compare Count properties for a fast exit if they are different.
            if (map.Count != other.map.Count)
            {
                return(false);
            }

            // Both key sets need to match exactly, but if Counts are equal a unidirectional check is sufficient.
            PValueEqualityComparer eq = PValueEqualityComparer.Instance;

            return(map.All(kv => other.map.TryGetValue(kv.Key, out PValue otherValue) &&
                           eq.AreEqual(kv.Value, otherValue)));
        }