Exemple #1
0
            public Expression <Action <TBase> > BuildSetterExpression <TBase>(TV value)
            {
                var setterExpression = _mapper.MapSetterValue(_memberExpression, value);

                var generator = new ExpressionGenerator(_mapper);

                var convertedType = setterExpression.Parameters[0].Type;

                var newParameter     = Expression.Parameter(typeof(TBase), setterExpression.Parameters[0].Name);
                var requiredVariable = generator.DeclareVariable(convertedType, "v");

                var replacedBody = setterExpression.GetBody(requiredVariable).Unwrap();

                generator.Assign(requiredVariable, newParameter);
                generator.AddExpression(replacedBody);

                var block = generator.Build();

                var resultExpression = Expression.Lambda <Action <TBase> >(block, newParameter);

                return(resultExpression);
            }
Exemple #2
0
            public Expression <Action <TBase, TV> > BuildSetterExpression <TBase>()
            {
                var generator = new ExpressionGenerator(_mapper);

                var propLambda    = _mapper.MapLambdaInternal(_memberExpression);
                var convertedType = propLambda.Parameters[0].Type;

                var newParameter     = Expression.Parameter(typeof(TBase), propLambda.Parameters[0].Name);
                var valueParameter   = Expression.Parameter(typeof(TV), "value");
                var requiredVariable = generator.DeclareVariable(convertedType, "v");

                generator.Assign(requiredVariable, newParameter);

                var left  = propLambda.GetBody(requiredVariable).Unwrap();
                var right = _mapper.BuildValueMapper(generator, valueParameter);

                generator.Assign(left, right);

                var generated = generator.Build();

                var resultLambda = Expression.Lambda <Action <TBase, TV> >(generated, newParameter, valueParameter);

                return(resultLambda);
            }