using System; using System.Collections.Generic; using System.Linq; namespace ScreenConnect; public struct HashableDictionaryWrapper(IDictionary? dictionary) : IEquatable> where TKey : notnull { public IDictionary? Dictionary { get; } = dictionary; public override int GetHashCode() { return HashCode.Seed.AndDictionary(Dictionary); } public override bool Equals(object? obj) { if (obj is HashableDictionaryWrapper other) { return Equals(other); } return false; } public bool Equals(HashableDictionaryWrapper other) { if (Dictionary != null || other.Dictionary != null) { if (Dictionary != null && other.Dictionary != null) { if (Dictionary.Count != 0 || other.Dictionary.Count != 0) { return Dictionary.Select((KeyValuePair it) => (Key: it.Key, Value: it.Value)).SequenceRangeEquals<(TKey, TValue)>(other.Dictionary.Select, (TKey, TValue)>((KeyValuePair it) => (Key: it.Key, Value: it.Value))); } return true; } return false; } return true; } }