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();
     }
 }
        public MappingStrategy BuildMappingStrategy(MappingInfo mappingInfo)
        {
            var strategy = new MappingStrategy(mappingInfo, descriptor);

            //first try to shortcircuit
            var directMappingStep = new DirectMappingStep(strategy.Source, strategy.Target);
            var converter = ApplyConverter(directMappingStep, withFallback: false);
            if (converter != null)
            {
                directMappingStep.Conversion = converter;
                strategy.InitTargetStep = directMappingStep;
                return strategy;
            }
            foreach (var pattern in mappingPatterns)
            {
                pattern.Contribute(strategy);
            }
            foreach (var mappingStep in strategy.MappingSteps)
            {
                mappingStep.Conversion = ApplyConverter(mappingStep, withFallback: true);
            }
            if (strategy.HasTargetInstance)
            {
                strategy.InitTargetStep = new SimpleStep(strategy.Target, strategy.Target, (s, _) => Expression.Convert(Expression.Property(s.ContextExpression, MappingContextMeta.TargetInstance), s.Target));
            }
            else
            {
                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 = ApplyConverter(mappingStep.Value, withFallback: true);
                }
                strategy.InitTargetStep = new SimpleStep(strategy.Target, strategy.Target, (s, _) => Expression.New(s.TargetConstructor, GetConstructorParameters(s)));
            }
            return strategy;
        }