Пример #1
0
        /// <summary>
        /// Create mapping rule to explicitly assign value to destination property
        /// </summary>
        /// <param name="destinationExpression">Expression for property to be set in destination type</param>
        /// <param name="value">Value to assign</param>
        /// <param name="condition">Conditition to be evaluated for determening if values should be set</param>
        /// <returns>Current instance of WaylessMap</returns>
        public ISetRuleBuilder <TDestination, TSource> FieldSet(Expression <Func <TDestination, object> > destinationExpression
                                                                , object value
                                                                , Expression <Func <TSource, bool> > setCondition)
        {
            var destination = GetMemberName(destinationExpression);

            if (!FieldSkips.Contains(destination))
            {
                IsFinalized = false;
                var expression = ExpressionBuilder.GetMapExressionForExplicitSet(destinationExpression, value, setCondition);

                RegisterFieldExpression(destination, expression);
            }
            return(this);
        }
Пример #2
0
        /// <summary>
        /// Create mapping rule for properties to be skipped in destination type
        /// </summary>
        /// <param name="ignoreAtDestinationExpression">Expression for property to be skipped in destination type</param>
        /// <returns>Current instance of WaylessMap</returns>
        public ISetRuleBuilder <TDestination, TSource> FieldSkip(Expression <Func <TDestination, object> > skipperName)
        {
            var ignore = GetMemberName(skipperName);

            if (!FieldSkips.Contains(ignore))
            {
                IsFinalized = false;
                FieldSkips.Add(ignore);
            }

            if (FieldExpressions.ContainsKey(ignore))
            {
                FieldExpressions.Remove(ignore);
            }

            return(this);
        }
Пример #3
0
        /// <summary>
        /// Performs call to MatchMaker if AutoMatchMembres is True
        /// </summary>
        public void FinalizeRules()
        {
            if (AutoMatchMembers)
            {
                if (MatchMaker == null)
                {
                    throw new NullReferenceException(nameof(MatchMaker));
                }

                var unmappedDestinations = DestinationFields.Where(x => !FieldExpressions.Keys.Contains(x.Key) &&
                                                                   !FieldSkips.Contains(x.Key))
                                           .Select(x => x.Value)
                                           .ToList();

                var matchedPairs = MatchMaker.FindMemberPairs(unmappedDestinations, SourceFields.Values);
                foreach (var pair in matchedPairs)
                {
                    var expression = ExpressionBuilder.GetMapExpression <TSource>(pair.DestinationMember, pair.SourceMember);
                    FieldExpressions.Add(pair.DestinationMember.Name, expression);
                }
            }

            IsFinalized = true;
        }