public override Expression GetPopulation(Expression value, IMemberMapperData mapperData)
        {
            if (mapperData.TargetMember.IsRecursion)
            {
                return(value);
            }

            if (this == _rootDictionaryMember)
            {
                return(base.GetPopulation(value, mapperData));
            }

            if (ValueIsFlattening(value, out var flattening))
            {
                return(flattening);
            }

            var keyedAccess = GetKeyedAccess(mapperData);

            var convertedValue =
                GetCheckedValueOrNull(value, keyedAccess, mapperData) ??
                mapperData.GetValueConversion(value, ValueType);

            var keyedAssignment = keyedAccess.AssignTo(convertedValue);

            return(keyedAssignment);
        }
        private static Expression GetConversionOrCreationExpression(
            this IMemberMapperData mapperData,
            Expression value,
            Type targetType,
            IList <ConfiguredObjectFactory> valueFactories)
        {
            var simpleMemberMapperData = SimpleMemberMapperData.Create(value, mapperData);

            var checkNestedAccesses =
                simpleMemberMapperData.TargetMemberIsEnumerableElement() &&
                value.Type.CanBeNull();

            var replacements = FixedSizeExpressionReplacementDictionary
                               .WithEquivalentKeys(3)
                               .Add(simpleMemberMapperData.SourceObject, value)
                               .Add(simpleMemberMapperData.TargetObject, mapperData.GetTargetMemberAccess())
                               .Add(simpleMemberMapperData.ElementIndex, simpleMemberMapperData.ElementIndexValue);

            var conversions = valueFactories.ProjectToArray(vf =>
            {
                var factoryExpression = vf.Create(simpleMemberMapperData);
                var condition         = vf.GetConditionOrNull(simpleMemberMapperData);

                if (checkNestedAccesses)
                {
                    var nestedAccessChecks = NestedAccessChecksFactory
                                             .GetNestedAccessChecksFor(factoryExpression);

                    if (nestedAccessChecks != null)
                    {
                        condition = condition != null
                            ? Expression.AndAlso(nestedAccessChecks, condition)
                            : nestedAccessChecks;
                    }
                }

                return(new SimpleTypeValueFactory
                {
                    Factory = factoryExpression.Replace(replacements).GetConversionTo(targetType),
                    Condition = condition?.Replace(replacements)
                });
            });

            if (conversions.Last().Condition != null)
            {
                conversions = conversions.Append(new SimpleTypeValueFactory
                {
                    Factory = mapperData.GetValueConversion(value, targetType) ??
                              simpleMemberMapperData.GetTargetMemberDefault()
                });
            }
            else if (conversions.Length == 1)
            {
                return(conversions[0].Factory);
            }

            return(GetConversionExpression(conversions));
        }
예제 #3
0
        private static Expression GetConvertedValue(Expression value, IMemberMapperData mapperData)
        {
            if (mapperData.TargetMember.IsComplex && !mapperData.TargetMember.Type.IsFromBcl())
            {
                return(value);
            }

            return(mapperData.GetValueConversion(value, mapperData.TargetMember.Type));
        }
예제 #4
0
 private SourceMemberDataSource(
     IQualifiedMember sourceMember,
     Expression sourceMemberValue,
     IMemberMapperData mapperData)
     : base(
         sourceMember,
         mapperData.GetValueConversion(sourceMemberValue, mapperData.TargetMember.Type),
         mapperData)
 {
     SourceMemberTypeTest = CreateSourceMemberTypeTest(sourceMemberValue, mapperData);
 }
        public static Expression GetValueConversionOrCreation(
            this IMemberMapperData mapperData,
            Expression value,
            Type targetType)
        {
            if (!mapperData.HasConfiguredSimpleTypeValueFactories())
            {
                return(mapperData.GetValueConversion(value, targetType));
            }

            var valueFactories = mapperData
                                 .QuerySimpleTypeValueFactories(value.Type, targetType)
                                 .ToArray();

            if (valueFactories.None())
            {
                return(mapperData.GetValueConversion(value, targetType));
            }

            return(mapperData.GetConversionOrCreationExpression(value, targetType, valueFactories));
        }
예제 #6
0
        public SourceMemberDataSource(
            IQualifiedMember sourceMember,
            Expression sourceMemberValue,
            Expression condition,
            IMemberMapperData mapperData)
            : base(
                sourceMember,
                mapperData.GetValueConversion(sourceMemberValue, mapperData.TargetMember.Type),
                mapperData)
        {
            SourceMemberTypeTest = CreateSourceMemberTypeTest(sourceMemberValue, mapperData);

            if (condition == null)
            {
                Condition = base.Condition;
                return;
            }

            Condition = IsConditional ? Expression.AndAlso(base.Condition, condition) : condition;
        }
 private Expression GetKey(IMemberMapperData mapperData)
 {
     return((Key?.NodeType != Parameter)
         ? mapperData.GetValueConversion(mapperData.GetTargetMemberDictionaryKey(), KeyType)
         : Key);
 }