protected ValueInjectionContext CreateContext(Type[] contextTypes, IMemberMapperData mapperData)
        {
            var args    = new ValueInjectionArgs(_lambda, _configInfo, contextTypes, mapperData);
            var context = args.GetAppropriateMappingContext();

            return(context);
        }
Exemple #2
0
 public ValueInjectionContext(
     ValueInjectionArgs args,
     Expression contextAccess,
     Expression sourceAccess,
     Expression targetAccess)
     : this(args, contextAccess)
 {
     _sourceAccess = sourceAccess;
     _targetAccess = targetAccess;
 }
        public Expression Inject(Type[] contextTypes, IMemberMapperData mapperData)
        {
            if (mapperData.MappingDataObject.Type.IsAssignableTo(_contextType))
            {
                return(_lambda.ReplaceParameterWith(mapperData.MappingDataObject));
            }

            var args    = new ValueInjectionArgs(_lambda, _configInfo, contextTypes, mapperData);
            var context = args.GetAppropriateMappingContext();

            if (_isMappingContextInvokeLambda)
            {
                return(args.GetInvocationContextArgument(context));
            }

            var targetContextTypes = _contextType.GetGenericTypeArguments();
            var contextType        = context.IsCallback(targetContextTypes) ? _contextType : _contextType.GetAllInterfaces().First();

            var requiredValues = GetRequiredValues();

            var replacements = FixedSizeExpressionReplacementDictionary
                               .WithEquivalentKeys(requiredValues.ValuesCount);

            if (requiredValues.Includes(Parent))
            {
                replacements.Add(PropertyAccess(nameof(Parent), contextType), context.GetParentAccess());
            }

            if (requiredValues.Includes(Source))
            {
                replacements.Add(PropertyAccess(RootSourceMemberName, contextType), context.GetSourceAccess());
            }

            if (requiredValues.Includes(Target))
            {
                replacements.Add(PropertyAccess(RootTargetMemberName, contextType), context.GetTargetAccess());
            }

            if (requiredValues.Includes(CreatedObject))
            {
                replacements.Add(PropertyAccess(nameof(CreatedObject), contextType), context.GetCreatedObject());
            }

            if (requiredValues.Includes(ElementIndex))
            {
                replacements.Add(PropertyAccess(nameof(ElementIndex), contextType), context.GetElementIndex());
            }

            if (requiredValues.Includes(ElementKey))
            {
                replacements.Add(PropertyAccess(nameof(ElementKey), contextType), context.GetElementKey());
            }

            return(_lambda.Body.Replace(replacements));
        }
Exemple #4
0
 public ValueInjectionContext(ValueInjectionArgs args, Expression contextAccess)
 {
     _args          = args;
     _contextAccess = contextAccess;
 }
Exemple #5
0
 public ValueInjectionContext(ValueInjectionArgs args)
     : this(args, args.MapperData.MappingDataObject)
 {
 }