| | | 1 | | // Copyright (c) 2020 .NET Foundation and Contributors. All rights reserved. |
| | | 2 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 3 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 4 | | // See the LICENSE file in the project root for full license information. |
| | | 5 | | |
| | | 6 | | using System; |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using ReactiveUI.Validation.States; |
| | | 9 | | |
| | | 10 | | namespace ReactiveUI.Validation.Comparators |
| | | 11 | | { |
| | | 12 | | /// <inheritdoc /> |
| | | 13 | | /// <summary> |
| | | 14 | | /// Utility class used to compare <see cref="ReactiveUI.Validation.States.ValidationState" /> instances. |
| | | 15 | | /// </summary> |
| | | 16 | | public class ValidationStateComparer : EqualityComparer<ValidationState> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Checks if two <see cref="ValidationState"/> objects are equals based on both |
| | | 20 | | /// <see cref="ValidationState.IsValid"/> and <see cref="ValidationState.Component"/> properties. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="x">Source <see cref="ValidationState"/> object.</param> |
| | | 23 | | /// <param name="y">Target <see cref="ValidationState"/> object.</param> |
| | | 24 | | /// <returns>Returns true if both objects are equals, otherwise false.</returns> |
| | | 25 | | public override bool Equals(ValidationState x, ValidationState y) |
| | | 26 | | { |
| | 50 | 27 | | if (x == null && y == null) |
| | | 28 | | { |
| | 0 | 29 | | return true; |
| | | 30 | | } |
| | | 31 | | |
| | 50 | 32 | | if (x == null || y == null) |
| | | 33 | | { |
| | 0 | 34 | | return false; |
| | | 35 | | } |
| | | 36 | | |
| | 50 | 37 | | return x.IsValid == y.IsValid && x.Text.ToSingleLine() == y.Text.ToSingleLine() |
| | 50 | 38 | | && x.Component == y.Component; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <inheritdoc /> |
| | | 42 | | public override int GetHashCode(ValidationState obj) |
| | | 43 | | { |
| | 0 | 44 | | if (obj == null) |
| | | 45 | | { |
| | 0 | 46 | | throw new ArgumentNullException(nameof(obj)); |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | return obj.GetHashCode(); |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |