using System.Text; namespace adas_core.Domain.Utils; /// /// Represents a comparable collection of key/value pairs that extends the standard dictionary functionality. /// /// The type of the keys in the dictionary, constrained to non-nullable types. /// The type of the values in the dictionary, constrained to non-nullable types. /// /// Inherits from and enforces that both keys and values are non-nullable. /// public class ComparableDictionary : Dictionary where TKey : notnull where TValue : notnull { /// /// Generates a hash code for the collection by concatenating the string representations of all key-value pairs, separated by underscores and double percent signs, and returning the hash code of the resulting string. /// /// An integer hash code derived from the concatenated key-value pairs of the collection. public override int GetHashCode() { StringBuilder str = new(); foreach (var item in this) { str.Append(item.Key); str.Append('_'); str.Append(item.Value); str.Append("%%"); } return str.ToString().GetHashCode(); } }