/// <summary> /// Determines whether two <see cref="ISpecimenBuilderNode" /> /// instances are define the same graph. /// </summary> /// <param name="first"> /// An <see cref="ISpecimenBuilderNode" /> to compare against /// <paramref name="second" />. /// </param> /// <param name="second"> /// An <see cref="ISpecimenBuilderNode" /> to compare against /// <paramref name="first" />. /// </param> /// <param name="comparer"> /// The comparer used to compare each node to another node. /// </param> /// <returns> /// <see langword="true" /> if the two /// <see cref="ISpecimenBuilderNode" /> define the same graph; /// otherwise, <see langword="false" />. /// </returns> /// <remarks> /// <para> /// Two <see cref="ISpecimenBuilderNode" /> instances define the same /// graph if they themselves are equal to each other, and all their /// child nodes recursively are equal to each other. Equality is /// defined by <paramref name="comparer" />. /// </para> /// </remarks> /// <exception cref="System.ArgumentNullException">first</exception> /// <exception cref="System.ArgumentNullException">second</exception> /// <exception cref="System.ArgumentNullException">comparer</exception> /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode)"/> public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second, IEqualityComparer <ISpecimenBuilder> comparer) { if (first == null) { throw new ArgumentNullException(nameof(first)); } if (second == null) { throw new ArgumentNullException(nameof(second)); } if (comparer == null) { throw new ArgumentNullException(nameof(comparer)); } if (!comparer.Equals(first, second)) { return(false); } using (IEnumerator <ISpecimenBuilder> e1 = first.GetEnumerator(), e2 = second.GetEnumerator()) { while (e1.MoveNext()) { if (!e2.MoveNext()) { return(false); } var n1 = e1.Current as ISpecimenBuilderNode; var n2 = e2.Current as ISpecimenBuilderNode; if (n1 != null && n2 != null) { if (!n1.GraphEquals(n2, comparer)) { return(false); } } else { if (n2 != null && n2.Any()) { return(false); } if (!comparer.Equals(e1.Current, e2.Current)) { return(false); } } } if (e2.MoveNext()) { return(false); } } return(true); }
/// <summary> /// Determines whether two <see cref="ISpecimenBuilderNode" /> /// instances are define the same graph. /// </summary> /// <param name="first"> /// An <see cref="ISpecimenBuilderNode" /> to compare against /// <paramref name="second" />. /// </param> /// <param name="second"> /// An <see cref="ISpecimenBuilderNode" /> to compare against /// <paramref name="first" />. /// </param> /// <param name="comparer"> /// The comparer used to compare each node to another node. /// </param> /// <returns> /// <see langword="true" /> if the two /// <see cref="ISpecimenBuilderNode" /> define the same graph; /// otherwise, <see langword="false" />. /// </returns> /// <remarks> /// <para> /// Two <see cref="ISpecimenBuilderNode" /> instances define the same /// graph if they themselves are equal to each other, and all their /// child nodes recursively are equal to each other. Equality is /// defined by <paramref name="comparer" />. /// </para> /// </remarks> /// <exception cref="System.ArgumentNullException">first</exception> /// <exception cref="System.ArgumentNullException">second</exception> /// <exception cref="System.ArgumentNullException">comparer</exception> /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode)"/> public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second, IEqualityComparer<ISpecimenBuilder> comparer) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); if (comparer == null) throw new ArgumentNullException(nameof(comparer)); if (!comparer.Equals(first, second)) return false; using (IEnumerator<ISpecimenBuilder> e1 = first.GetEnumerator(), e2 = second.GetEnumerator()) { while (e1.MoveNext()) { if (!e2.MoveNext()) return false; var n1 = e1.Current as ISpecimenBuilderNode; var n2 = e2.Current as ISpecimenBuilderNode; if (n1 != null && n2 != null) { if (!n1.GraphEquals(n2, comparer)) return false; } else { if (n2 != null && n2.Any()) return false; if (!comparer.Equals(e1.Current, e2.Current)) return false; } } if (e2.MoveNext()) return false; } return true; }