예제 #1
0
        public IEnumerable <ExpressionSyntax> MapUsingSimpleAssignment(SyntaxGenerator generator,
                                                                       IEnumerable <IPropertySymbol> targets, IMappingSourceFinder sourceFinder,
                                                                       MappingPath mappingPath = null, SyntaxNode globalTargetAccessor = null)
        {
            if (mappingPath == null)
            {
                mappingPath = new MappingPath();
            }

            return(targets.Select(property => new
            {
                source = sourceFinder.FindMappingSource(property.Name, property.Type),
                target = new MappingElement()
                {
                    Expression = (ExpressionSyntax)CreateAccessPropertyExpression(globalTargetAccessor, property, generator),
                    ExpressionType = property.Type
                }
            })
                   .Where(x => x.source != null)
                   .Select(pair =>
            {
                var sourceExpression = this.MapExpression(pair.source, pair.target.ExpressionType, mappingPath.Clone()).Expression;
                return (ExpressionSyntax)generator.AssignmentStatement(pair.target.Expression, sourceExpression);
            }).ToList());
        }
        public MappingElement FindMappingSource(string targetName, ITypeSymbol targetType,
                                                MappingContext mappingContext)
        {
            var mapping = wrappedFinder.FindMappingSource(targetName, targetType, mappingContext);

            return(mapping == null || ignore(mapping) ? null : mapping);
        }
예제 #3
0
 public IReadOnlyList <MappingMatch> MatchAll(IEnumerable <IPropertySymbol> targets, SyntaxGenerator syntaxGenerator, SyntaxNode globalTargetAccessor = null)
 {
     return(targets.Select(property => new MappingMatch
     {
         Source = sourceFinder.FindMappingSource(property.Name, property.Type),
         Target = CreateTargetElement(globalTargetAccessor, property, syntaxGenerator)
     })
            .Where(x => x.Source != null).ToList());
 }
 public IReadOnlyList <MappingMatch> MatchAll(IReadOnlyCollection <IObjectField> targets,
                                              SyntaxGenerator syntaxGenerator, MappingContext mappingContext, SyntaxNode globalTargetAccessor = null)
 {
     return(targets.Select(target => new MappingMatch
     {
         Source = sourceFinder.FindMappingSource(target.Name, target.Type, mappingContext),
         Target = CreateTargetElement(globalTargetAccessor, target, syntaxGenerator)
     })
            .Where(x => x.Source != null).ToList());
 }
예제 #5
0
        private static MatchedParameterList FindArgumentsMatch(ImmutableArray <IParameterSymbol> parameters, IMappingSourceFinder mappingSourceFinder)
        {
            var matchedArgumentList = new MatchedParameterList();

            foreach (var parameter in parameters)
            {
                var mappingSource = mappingSourceFinder.FindMappingSource(parameter.Name, parameter.Type);
                matchedArgumentList.AddMatch(parameter, mappingSource);
            }
            return(matchedArgumentList);
        }
예제 #6
0
        private static async Task <MatchedParameterList> FindArgumentsMatch(ImmutableArray <IParameterSymbol> parameters,
                                                                            IMappingSourceFinder mappingSourceFinder, MappingContext mappingContext)
        {
            var matchedArgumentList = new MatchedParameterList();

            foreach (var parameter in parameters)
            {
                var mappingSource = await mappingSourceFinder.FindMappingSource(parameter.Name, new AnnotatedType(parameter.Type), mappingContext).ConfigureAwait(false);

                matchedArgumentList.AddMatch(parameter, mappingSource);
            }
            return(matchedArgumentList);
        }
        public async Task <IReadOnlyList <MappingMatch> > MatchAll(IReadOnlyCollection <IObjectField> targets, SyntaxGenerator syntaxGenerator, MappingContext mappingContext, SyntaxNode globalTargetAccessor = null)
        {
            var results = new List <MappingMatch>(targets.Count);

            foreach (var target in targets)
            {
                results.Add(new MappingMatch
                {
                    Source = await sourceFinder.FindMappingSource(target.Name, target.Type, mappingContext).ConfigureAwait(false),
                    Target = CreateTargetElement(globalTargetAccessor, target, syntaxGenerator)
                });
            }

            return(results.Where(x => x.Source != null).ToList());
        }
        public MappingElement FindMappingSource(string targetName, ITypeSymbol targetType)
        {
            var mapping = wrappedFinder.FindMappingSource(targetName, targetType);

            return(ignore(mapping) ? null : mapping);
        }
        public async Task <MappingElement> FindMappingSource(string targetName, AnnotatedType targetType, MappingContext mappingContext)
        {
            var mapping = await wrappedFinder.FindMappingSource(targetName, targetType, mappingContext).ConfigureAwait(false);

            return(mapping == null || ignore(mapping) ? null : mapping);
        }