mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
32 lines
1 KiB
C#
32 lines
1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace ShareeBike.Repository.Response
|
|
{
|
|
/// <summary>
|
|
/// Holds a dictionary of comparable elements.
|
|
/// </summary>
|
|
/// <typeparam name="S">Type of the element.</typeparam>
|
|
[DataContract]
|
|
public class ComparableDictionary<S> : Dictionary<string, S>, IEquatable<ComparableDictionary<S>>
|
|
{
|
|
public bool Equals(ComparableDictionary<S> other)
|
|
{
|
|
return this.OrderBy(x => x.Key).SequenceEqual(other.OrderBy(x => x.Key));
|
|
}
|
|
|
|
public static bool operator ==(ComparableDictionary<S> first, ComparableDictionary<S> second)
|
|
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
|
|
|
|
public static bool operator !=(ComparableDictionary<S> first, ComparableDictionary<S> second)
|
|
=> !(first == second);
|
|
|
|
public override bool Equals(object obj) => obj is ComparableDictionary<S> target && target == this;
|
|
|
|
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
|
|
|
|
}
|
|
}
|