/// <summary>Indicates whether the current object is equal to another object of the same type.</summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns> public bool Equals(JsonSchema other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (BoolValue.HasValue) { return(BoolValue == other.BoolValue); } if (other.BoolValue.HasValue) { return(false); } if (Keywords.Count != other.Keywords.Count) { return(false); } if (OtherData?.Count != other.OtherData?.Count) { return(false); } if (Keywords != null) { var byKeyword = Keywords.Join(other.Keywords, tk => tk.Keyword(), ok => ok.Keyword(), (tk, ok) => new { ThisKeyword = tk, OtherKeyword = ok }) .ToList(); if (byKeyword.Count != Keywords.Count) { return(false); } if (!byKeyword.All(k => k.ThisKeyword.Equals(k.OtherKeyword))) { return(false); } } if (OtherData != null) { var byKey = OtherData.Join(other.OtherData, td => td.Key, od => od.Key, (td, od) => new { ThisData = td.Value, OtherData = od.Value }) .ToList(); if (byKey.Count != OtherData.Count) { return(false); } if (!byKey.All(k => k.ThisData.IsEquivalentTo(k.OtherData))) { return(false); } } return(true); }