public TypeMappingSpec <TTarget, TSource> UsingMapping( Func <TypeMappingSpec <TNestedMappingTarget, TSource>, TypeMappingSpec <TNestedMappingTarget, TSource> > nestedSpecTransform) { var previouslyUnmatchedSourceNames = new HashSet <string>( NestedSpec.GetUnmappedSourceValues().Select(x => x.PropertyName) ); var finalNestedSpec = nestedSpecTransform(NestedSpec); var unmatchedSourceNames = new HashSet <string>( finalNestedSpec.GetUnmappedSourceValues() .Select(x => x.PropertyName) ); var customMappedSourceNames = previouslyUnmatchedSourceNames .Except(unmatchedSourceNames); finalNestedSpec = finalNestedSpec .WithSourceValues( finalNestedSpec.SourceValues .Where(x => !unmatchedSourceNames.Contains(x.PropertyName))); var nestedMapper = finalNestedSpec.Create(); var nestedSourceValueNames = new HashSet <string>( finalNestedSpec.SourceValues.Select(x => x.PropertyName)); nestedSourceValueNames.UnionWith(customMappedSourceNames); return(Spec .ThatSets(TargetPropertyExpression).From(src => TargetMapFunction(nestedMapper.Map(src))) .WithSourceValues( Spec.SourceValues .Where(x => !nestedSourceValueNames.Contains(x.PropertyName)))); }
public ExpandIntoNestedTargetSpec <TTarget, TSource, TTargetProperty, TNestedMappingTarget> WithConstructor(Func <TNestedMappingTarget> constructor) { return(new ExpandIntoNestedTargetSpec <TTarget, TSource, TTargetProperty, TNestedMappingTarget>( Spec, TargetPropertyExpression, NestedSpec.WithConstructor(constructor), TargetMapFunction )); }