public void Apply(MappingStrategy strategy, MappingStrategyBuildContext context) { foreach (var mappingStep in strategy.MappingSteps) { mappingStep.Conversion = context.ApplyConverter(mappingStep, withFallback: true); } }
public void Apply(MappingStrategy strategy, MappingStrategyBuildContext context) { if (strategy.HasTargetInstance) { strategy.InitTargetStep = new SimpleStep(strategy.Target, strategy.Target, (s, _) => Expression.Convert(Expression.Property(s.ContextExpression, MappingContextMeta.TargetInstance), s.Target)); } else { if (strategy.TargetConstructor == null) { throw new ArgumentException("Constructor not set. This exception message is a work in progress"); } if (strategy.ConstructorParameterMappingSteps == null) { throw new ArgumentException("ConstructorParameterMappingSteps not set. This exception message is a work in progress"); } foreach (var mappingStep in strategy.ConstructorParameterMappingSteps.ByKey) { if (mappingStep.Value == null) { throw new InvalidOperationException(String.Format("No mapping for constructor parameter {0} has been specified. All constructor parameters need value", mappingStep.Key)); } mappingStep.Value.Conversion = context.ApplyConverter(mappingStep.Value, withFallback: true); } strategy.InitTargetStep = new SimpleStep(strategy.Target, strategy.Target, (s, _) => Expression.New(s.TargetConstructor, GetConstructorParameters(s))); } }
public void Apply(MappingStrategy strategy, MappingStrategyBuildContext context) { var directMappingStep = new DirectMappingStep(strategy.Source, strategy.Target); var converter = context.ApplyConverter(directMappingStep, withFallback: false); if (converter != null) { directMappingStep.Conversion = converter; strategy.InitTargetStep = directMappingStep; context.MarkAsCompleted(); } }