private ConfiguredLambdaInfo GetValueLambdaInfo(Type targetValueType)
        {
            if (_customValueLambdaInfo != null)
            {
                return(_customValueLambdaInfo);
            }
#if NET35
            var            customValueLambda = _customValueLambda.ToDlrExpression();
            const ExprType CONSTANT          = ExprType.Constant;
#else
            var            customValueLambda = _customValueLambda;
            const ExprType CONSTANT          = Constant;
#endif
            if ((customValueLambda.Body.NodeType != CONSTANT) ||
                (targetValueType == typeof(object)) ||
                customValueLambda.ReturnType.IsAssignableTo(targetValueType) ||
                _configInfo.HasTargetMemberMatcher())
            {
                return(_customValueLambdaInfo = ConfiguredLambdaInfo.For(customValueLambda, _configInfo));
            }

            var convertedConstantValue = MapperContext
                                         .GetValueConversion(customValueLambda.Body, targetValueType);

            var funcType            = Expr.GetFuncType(targetValueType);
            var valueLambda         = Expr.Lambda(funcType, convertedConstantValue);
            var valueFunc           = valueLambda.Compile();
            var value               = valueFunc.DynamicInvoke().ToConstantExpression(targetValueType);
            var constantValueLambda = Expr.Lambda(funcType, value);
            var valueLambdaInfo     = ConfiguredLambdaInfo.For(constantValueLambda, _configInfo);

            return(_customValueLambdaInfo = valueLambdaInfo);
        }
예제 #2
0
 public static ConfiguredObjectFactory For(MappingConfigInfo configInfo, Type objectType, LambdaExpression factory)
 => For(configInfo, objectType, ConfiguredLambdaInfo.For(factory));
 internal CustomDataSourceTargetMemberSpecifier(MappingConfigInfo configInfo, LambdaExpression customValueLambda)
     : this(configInfo, ConfiguredLambdaInfo.For(customValueLambda))
 {
 }