コード例 #1
0
            protected override Expression GetFilterExpression(Expression sourceValue, ref bool hasFixedValueOperands)
            {
                var conditionReplacements = FixedSizeExpressionReplacementDictionary.WithEqualKeys(_filterConditions.Count);

                foreach (var filterCondition in _filterConditions)
                {
                    conditionReplacements.Add(
                        filterCondition.Filter,
                        filterCondition.GetConditionReplacement(sourceValue, ref hasFixedValueOperands));
                }

                return(ValuesFilter.Replace(conditionReplacements));
            }
コード例 #2
0
            public override Expression Inject(Type[] contextTypes, IMemberMapperData mapperData)
            {
                var replacements = _isInvocation
                    ? FixedSizeExpressionReplacementDictionary.WithEqualKeys(RequiredValuesCount)
                    : FixedSizeExpressionReplacementDictionary.WithEquivalentKeys(RequiredValuesCount);

                var context = CreateContext(contextTypes, mapperData);

                if (_requiredValues.Includes(MappingContext))
                {
                    replacements.Add(_requiredValues.MappingContext, context.GetMappingDataAccess());
                }

                if (_requiredValues.Includes(Source))
                {
                    replacements.Add(_requiredValues.Source, context.GetSourceAccess());
                }

                if (_requiredValues.Includes(Target))
                {
                    replacements.Add(_requiredValues.Target, context.GetTargetAccess());
                }

                if (_requiredValues.Includes(CreatedObject))
                {
                    replacements.Add(_requiredValues.CreatedObject, context.GetCreatedObject());
                }

                if (_requiredValues.Includes(ElementIndex))
                {
                    replacements.Add(_requiredValues.ElementIndex, context.GetElementIndex());
                }

                if (_requiredValues.Includes(ElementKey))
                {
                    replacements.Add(_requiredValues.ElementKey, context.GetElementKey());
                }

                return(_lambdaBody.Replace(replacements));
            }
        protected override Expression GetTargetObjectCreation(
            IObjectMappingData mappingData,
            IList <Expression> memberPopulations)
        {
            var objectCreation = base.GetTargetObjectCreation(mappingData, memberPopulations);

            if (objectCreation == null)
            {
                memberPopulations.Clear();
                return(null);
            }

            if (memberPopulations.None())
            {
                return(objectCreation);
            }

            var memberBindings = GetMemberBindingsFrom(memberPopulations);

            if (memberBindings.None())
            {
                return(objectCreation);
            }

            var objectNewings      = NewExpressionFinder.FindIn(objectCreation);
            var newingReplacements = FixedSizeExpressionReplacementDictionary.WithEqualKeys(objectNewings.Count);

            foreach (var objectNewing in objectNewings)
            {
                var objectInit = Expression.MemberInit(objectNewing, memberBindings);

                newingReplacements.Add(objectNewing, objectInit);
            }

            var fullObjectInit = objectCreation.Replace(newingReplacements);

            return(fullObjectInit);
        }