| | | 1 | | using Elsa.Workflows.Activities.Flowchart.Models; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.Activities.Flowchart.Serialization; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Compares two <see cref="Connection"/> instances. |
| | | 7 | | /// </summary> |
| | | 8 | | public class ConnectionComparer : IEqualityComparer<Connection> |
| | | 9 | | { |
| | | 10 | | /// <inheritdoc /> |
| | | 11 | | public bool Equals(Connection? x, Connection? y) |
| | | 12 | | { |
| | 2 | 13 | | if (ReferenceEquals(x, y)) return true; |
| | 0 | 14 | | if (ReferenceEquals(x, null)) return false; |
| | 0 | 15 | | if (ReferenceEquals(y, null)) return false; |
| | 0 | 16 | | if (x.GetType() != y.GetType()) return false; |
| | | 17 | | |
| | | 18 | | // ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract |
| | | 19 | | // Justification: These can be null when the designer is in an invalid state. For example, if a NotFoundActivity |
| | 0 | 20 | | if (x.Source.Activity?.Id == null || x.Target.Activity?.Id == null || y.Source.Activity?.Id == null || y.Target. |
| | 0 | 21 | | return false; |
| | | 22 | | // ReSharper restore ConditionalAccessQualifierIsNonNullableAccordingToAPIContract |
| | | 23 | | |
| | 0 | 24 | | return x.Source.Activity.Id.Equals(y.Source.Activity.Id) && x.Target.Activity.Id.Equals(y.Target.Activity.Id) && |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public int GetHashCode(Connection obj) |
| | | 29 | | { |
| | | 30 | | // ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract |
| | | 31 | | // Justification: These can be null when the designer is in an invalid state. For example, if it used a NotFound |
| | 945 | 32 | | return HashCode.Combine(obj.Source?.Activity?.Id, obj.Target?.Activity?.Id, obj.Source?.Port, obj.Target?.Port); |
| | | 33 | | // ReSharper restore ConditionalAccessQualifierIsNonNullableAccordingToAPIContract |
| | | 34 | | } |
| | | 35 | | } |