コード例 #1
0
    public StructuralEqualityComparer(Func <PropertyInfo, bool> excludePredicate = null, StructuralEqualityComparerOptions options = null)
    {
        Func <PropertyInfo, bool> defaultExcludePredicate = (propertyInfo) => false;

        _excludePredicate = excludePredicate ?? defaultExcludePredicate;
        _options          = options;
    }
コード例 #2
0
        /// <summary>
        /// Adds a matching criterion to the structural equality comparer.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The enumerations of values returned by the accessor are compared by using the specified comparer.
        /// </para>
        /// </remarks>
        /// <example>
        /// <code><![CDATA[
        /// public class Foo
        /// {
        ///     public int[] Values;
        /// }
        ///
        /// [TestFixture]
        /// public class FooTest
        /// {
        ///     [Test]
        ///     public void MyTest()
        ///     {
        ///         var foo1 = new Foo() { Values = new int[] { 1, 2, 3, 4, 5 } };
        ///         var foo2 = new Foo() { Values = new int[] { 5, 4, 3, 2, 1 } };
        ///
        ///         Assert.AreEqual(foo1, foo2, new StructuralEqualityComparer<Foo>
        ///         {
        ///             { x => x.Values,
        ///               new StructuralEqualityComparer<int> { { x => x } },
        ///               StructuralEqualityComparerOptions.IgnoreEnumerableOrder
        ///             },
        ///         });
        ///     }
        /// }
        /// ]]></code>
        /// </example>
        /// <typeparam name="TValue">The type of the value returned by the accessor.</typeparam>
        /// <param name="accessor">An accessor that gets an enumeration of values from the tested object.</param>
        /// <param name="comparer">A comparer instance for the values returned by the accessor, or null to use the default one.</param>
        /// <param name="options">Some options indicating how to compare the enumeration of values returned by the accessor.</param>
        /// <exception cref="ArgumentNullException">The specified accessor argument is a null reference.</exception>
        public void Add <TValue>(Accessor <T, IEnumerable <TValue> > accessor, EqualityComparison <TValue> comparer, StructuralEqualityComparerOptions options)
        {
            if (comparer == null)
            {
                comparer = ComparisonSemantics.Default.Equals <TValue>;
            }

            if ((options & StructuralEqualityComparerOptions.IgnoreEnumerableOrder) != 0)
            {
                conditions.Add((x, y) => CompareEnumerablesIgnoringOrder(accessor(x), accessor(y), comparer));
            }
            else
            {
                conditions.Add((x, y) => CompareEnumerables(accessor(x), accessor(y), comparer));
            }
        }
コード例 #3
0
 /// <summary>
 /// Adds a matching criterion to the structural equality comparer.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The enumerations of values returned by the accessor are compared by using the specified comparer.
 /// </para>
 /// </remarks>
 /// <example>
 /// <code><![CDATA[
 /// public class Foo
 /// {
 ///     public int[] Values;
 /// }
 ///
 /// [TestFixture]
 /// public class FooTest
 /// {
 ///     [Test]
 ///     public void MyTest()
 ///     {
 ///         var foo1 = new Foo() { Values = new int[] { 1, 2, 3, 4, 5 } };
 ///         var foo2 = new Foo() { Values = new int[] { 5, 4, 3, 2, 1 } };
 ///
 ///         Assert.AreEqual(foo1, foo2, new StructuralEqualityComparer<Foo>
 ///         {
 ///             { x => x.Values,
 ///               new StructuralEqualityComparer<int> { { x => x } },
 ///               StructuralEqualityComparerOptions.IgnoreEnumerableOrder
 ///             },
 ///         });
 ///     }
 /// }
 /// ]]></code>
 /// </example>
 /// <typeparam name="TValue">The type of the value returned by the accessor.</typeparam>
 /// <param name="accessor">An accessor that gets an enumeration of values from the tested object.</param>
 /// <param name="comparer">A comparer instance for the values returned by the accessor, or null to use the default one.</param>
 /// <param name="options">Some options indicating how to compare the enumeration of values returned by the accessor.</param>
 /// <exception cref="ArgumentNullException">The specified accessor argument is a null reference.</exception>
 public void Add <TValue>(Accessor <T, IEnumerable <TValue> > accessor, IEqualityComparer <TValue> comparer, StructuralEqualityComparerOptions options)
 {
     Add(accessor, (comparer ?? StructuralEqualityComparer <TValue> .Default).Equals, options);
 }