private Expression CreateAssignmentFunc(Expression destinationFunc, bool constructorMapping) { var actions = new List <Expression>(); foreach (var propertyMap in _typeMap.GetPropertyMaps().Where(pm => pm.CanResolveValue())) { var property = TryPropertyMap(propertyMap); if (constructorMapping && _typeMap.ConstructorParameterMatches(propertyMap.DestinationProperty.Name)) { property = _initialDestination.IfNullElse(Empty(), property); } actions.Add(property); } foreach (var pathMap in _typeMap.PathMaps.Where(pm => !pm.Ignored)) { actions.Add(HandlePath(pathMap)); } foreach (var beforeMapAction in _typeMap.BeforeMapActions) { actions.Insert(0, beforeMapAction.ReplaceParameters(Source, _destination, Context)); } actions.Insert(0, destinationFunc); if (_typeMap.MaxDepth > 0) { actions.Insert(0, Call(Context, ((MethodCallExpression)IncTypeDepthInfo.Body).Method, Constant(_typeMap.Types))); } if (_typeMap.IsConventionMap && _typeMap.Profile.ValidateInlineMaps) { actions.Insert(0, Call(Context, ((MethodCallExpression)ValidateMap.Body).Method, Constant(_typeMap))); } actions.AddRange( _typeMap.AfterMapActions.Select( afterMapAction => afterMapAction.ReplaceParameters(Source, _destination, Context))); if (_typeMap.MaxDepth > 0) { actions.Add(Call(Context, ((MethodCallExpression)DecTypeDepthInfo.Body).Method, Constant(_typeMap.Types))); } actions.Add(_destination); return(Block(actions)); }
private Expression CreateAssignmentFunc(Expression destinationFunc, bool constructorMapping) { var actions = new List <Expression>(); foreach (var propertyMap in _typeMap.GetPropertyMaps()) { if (!propertyMap.CanResolveValue()) { continue; } var property = TryPropertyMap(propertyMap); if (constructorMapping && _typeMap.ConstructorParameterMatches(propertyMap.DestinationProperty.Name)) { property = IfThen(NotEqual(_initialDestination, Constant(null)), property); } actions.Add(property); } foreach (var pathMap in _typeMap.PathMaps) { actions.Add(HandlePath(pathMap)); } foreach (var beforeMapAction in _typeMap.BeforeMapActions) { actions.Insert(0, beforeMapAction.ReplaceParameters(_source, _destination, _context)); } actions.Insert(0, destinationFunc); if (_typeMap.MaxDepth > 0) { actions.Insert(0, Call(_context, ((MethodCallExpression)IncTypeDepthInfo.Body).Method, Constant(_typeMap.Types))); } actions.AddRange( _typeMap.AfterMapActions.Select( afterMapAction => afterMapAction.ReplaceParameters(_source, _destination, _context))); if (_typeMap.MaxDepth > 0) { actions.Add(Call(_context, ((MethodCallExpression)DecTypeDepthInfo.Body).Method, Constant(_typeMap.Types))); } actions.Add(_destination); return(Block(actions)); }
private static Expression CreateAssignmentFunc( TypeMap typeMap, IConfigurationProvider configurationProvider, TypeMapRegistry registry, ParameterExpression srcParam, ParameterExpression destParam, ParameterExpression ctxtParam, Expression destinationFunc, ParameterExpression destination, bool constructorMapping) { var actions = new List<Expression>(); foreach(var propertyMap in typeMap.GetPropertyMaps()) { if(!propertyMap.CanResolveValue()) { continue; } var property = TryPropertyMap(propertyMap, configurationProvider, registry, srcParam, destination, ctxtParam); if(constructorMapping && typeMap.ConstructorParameterMatches(propertyMap.DestinationProperty.Name)) { property = IfThen(NotEqual(destParam, Expression.Constant(null)), property); } actions.Add(property); } foreach (var beforeMapAction in typeMap.BeforeMapActions) { actions.Insert(0, beforeMapAction.ReplaceParameters(srcParam, destination, ctxtParam)); } actions.Insert(0, destinationFunc); if (typeMap.MaxDepth > 0) { actions.Insert(0, Call(ctxtParam, ((MethodCallExpression)IncTypeDepthInfo.Body).Method, Constant(typeMap.Types))); } actions.AddRange( typeMap.AfterMapActions.Select( afterMapAction => afterMapAction.ReplaceParameters(srcParam, destination, ctxtParam))); if (typeMap.MaxDepth > 0) { actions.Add(Call(ctxtParam, ((MethodCallExpression)DecTypeDepthInfo.Body).Method, Constant(typeMap.Types))); } actions.Add(destination); return Block(actions); }