using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
///
/// Holds a dictionary of comparable elements.
///
/// Type of the element.
[DataContract]
public class ComparableDictionary : Dictionary, IEquatable>
{
public bool Equals(ComparableDictionary other)
{
return this.OrderBy(x => x.Key).SequenceEqual(other.OrderBy(x => x.Key));
}
public static bool operator ==(ComparableDictionary first, ComparableDictionary second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(ComparableDictionary first, ComparableDictionary second)
=> !(first == second);
public override bool Equals(object obj) => obj is ComparableDictionary target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}