I've got this, but it's so short I'm nearly sure I'm missing something:
public static bool ValueEquals<TKey, TValue>
(this IDictionary<TKey, TValue> source, IDictionary<TKey, TValue> toCheck)
{
if (object.ReferenceEquals(source, toCheck))
return true;
if (source == null || toCheck == null || source.Count != toCheck.Count)
return false;
return source.OrderBy(t => t.Key).SequenceEqual(toCheck.OrderBy(t => t.Key));
}
So basically, if they have an equal reference, return true
. If either of them are null
or their counts are different, return false
. Then return if the sequences (ordered by their keys and then their values) are the same. I must be missing something, as it's far too short to be good enough.