Exemple #1
0
        public bool Compare(JPropertyKeyedCollection other)
        {
            if (this == other)
            {
                return(true);
            }

            // dictionaries in JavaScript aren't ordered
            // ignore order when comparing properties
            Dictionary <string, JToken> d1 = _dictionary;
            Dictionary <string, JToken> d2 = other._dictionary;

            if (d1 == null && d2 == null)
            {
                return(true);
            }

            if (d1 == null)
            {
                return(d2.Count == 0);
            }

            if (d2 == null)
            {
                return(d1.Count == 0);
            }

            if (d1.Count != d2.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <string, JToken> keyAndProperty in d1)
            {
                if (!d2.TryGetValue(keyAndProperty.Key, out JToken secondValue))
                {
                    return(false);
                }

                JProperty p1 = (JProperty)keyAndProperty.Value;
                JProperty p2 = (JProperty)secondValue;

                if (p1.Value == null)
                {
                    return(p2.Value == null);
                }

                if (!p1.Value.DeepEquals(p2.Value))
                {
                    return(false);
                }
            }

            return(true);
        }