/// <summary>
        /// Initializes a new instance of the <see cref="EqualityComparerHelperStrategyToManyRelationshipComparer{TModel,TTargetModel,TComparerIntention}"/> class.
        /// </summary>
        public EqualityComparerHelperStrategyToManyRelationshipComparer(
            Expression <Func <TModel, IEnumerable <TTargetModel> > > expression,
            IComparer <TTargetModel, TComparerIntention> comparer)
        {
            expression.NotNull(nameof(expression));
            comparer.NotNull(nameof(comparer));

            this.func         = expression.Compile();
            this.propertyName = EqualityComparerHelperStrategyUtils.GetMethodName(expression);
            this.comparer     = comparer;
        }
        /// <inheritdoc/>
        public bool IsElementEqualsOrExcluded(
            TModel candidate1,
            TModel candidate2,
            ICollection <IBaseAdditionalProcessing> additionalProcessings,
            IEnumerable <IComparerExclusion> exclusions)
        {
            if (EqualityComparerHelperStrategyUtils.IsPropertyExcluded(exclusions, typeof(TModel), this.propertyName))
            {
                return(true);
            }

            var value1 = this.func.Invoke(candidate1) as TTargetModel;
            var value2 = this.func.Invoke(candidate2) as TTargetModel;

            return(this.comparer.Equals(value1, value2, additionalProcessings, exclusions));
        }
        /// <inheritdoc/>
        public bool IsElementEqualsOrExcluded(
            TModel candidate1,
            TModel candidate2,
            ICollection <IBaseAdditionalProcessing> additionalProcessings,
            IEnumerable <IComparerExclusion> exclusions)
        {
            if (EqualityComparerHelperStrategyUtils.IsPropertyExcluded(exclusions, typeof(TModel), this.propertyName))
            {
                return(true);
            }

            var valuesCandidate1 = this.func.Invoke(candidate1);
            var valuesCandidate2 = this.func.Invoke(candidate2);

            var result = EqualityComparerHelperStrategyUtils.AreListEquivalent(
                valuesCandidate1,
                valuesCandidate2,
                (x, y) => this.comparer.Equals(x, y, additionalProcessings, exclusions));

            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EqualityComparerHelperStrategySubCompareComparer{T,TComparerIntention}"/> class.
 /// </summary>
 public EqualityComparerHelperStrategySubCompareComparer(IComparer <T, TIntention> comparer)
 {
     comparer.NotNull(nameof(comparer));
     this.comparer        = comparer;
     this.subComparerType = EqualityComparerHelperStrategyUtils.GetCompareType(comparer);
 }