예제 #1
0
        public void ExtendWith(ExpressionBuilder <TSource, TDest> other)
        {
            if (other == null)
            {
                return;
            }

            var otherPropertyBindings = other.GetPropertyBindings();

            if (otherPropertyBindings.Count == 0)
            {
                return;
            }

            var sourceParamExp       = this.GetSourceParam();
            var otherParamExp        = other.GetSourceParam();
            var sourceReplacer       = new SourceParamReplacer(otherParamExp, sourceParamExp);
            var thisPropertyBindings = this.GetPropertyBindings();

            foreach (var runtimeBinding in otherPropertyBindings)
            {
                var replaced = VisitMember(runtimeBinding.Value, sourceReplacer);
                thisPropertyBindings[runtimeBinding.Key] = replaced;
            }

            this.ResetExpression(); //delayed exp creation
        }
        public StaticMapCreator(ParameterExpression sourceParameter, Expression <Func <TSource, TDest> > expression)
        {
            if (sourceParameter == null || expression == null)
            {
                throw new ArgumentNullException("StaticMapCreator: sourceParameter || expression");
            }

            //Save static map WITHOUT expanding 'InvokeMap' calls (which will happen in runtime)
            //Sets the source parameter during configuration set-up, so we don't need to replace it later.
            var paramReplacer = new SourceParamReplacer(expression.Parameters[0], sourceParameter);

            _expression = (Expression <Func <TSource, TDest> >)paramReplacer.Visit(expression);
        }