public IEnumerable <SyntaxNode> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel)
        {
            var mappingEngine = new MappingEngine(semanticModel, generator, methodSymbol.ContainingAssembly);
            var sourceFinder  = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol.Parameters);
            var targets       = ObjectHelper.GetFieldsThaCanBeSetPrivately(methodSymbol.ContainingType);

            return(mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder)));
        }
        public IEnumerable <SyntaxNode> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
                                                               SemanticModel semanticModel, MappingContext mappingContext)
        {
            var mappingEngine = new MappingEngine(semanticModel, generator);
            var sourceFinder  = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol.Parameters);
            var targets       = MappingTargetHelper.GetFieldsThaCanBeSetFromConstructor(methodSymbol.ContainingType, mappingContext);

            return(mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext));
        }
Esempio n. 3
0
        public IEnumerable <SyntaxNode> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel)
        {
            var mappingEngine = new MappingEngine(semanticModel, generator, methodSymbol.ContainingAssembly);
            var source        = methodSymbol.Parameters[0];
            var sourceFinder  = new ObjectMembersMappingSourceFinder(source.Type, generator.IdentifierName(source.Name), generator);
            var targets       = ObjectHelper.GetFieldsThaCanBeSetFromConstructor(methodSymbol.ContainingType);

            return(mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder)));
        }
Esempio n. 4
0
        public async Task <IReadOnlyList <SyntaxNode> > GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
                                                                               SemanticModel semanticModel, MappingContext mappingContext)
        {
            var mappingEngine       = new MappingEngine(semanticModel, generator);
            var sourceFinder        = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol.Parameters);
            var mappingTargetHelper = new MappingTargetHelper();
            var targets             = mappingTargetHelper.GetFieldsThaCanBeSetFromConstructor(methodSymbol.ContainingType, mappingContext);

            return(await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext).ConfigureAwait(false));
        }
Esempio n. 5
0
        public IEnumerable <SyntaxNode> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
                                                               SemanticModel semanticModel, MappingContext mappingContext)
        {
            var mappingEngine = new MappingEngine(semanticModel, generator);
            var source        = methodSymbol.Parameters[0];
            var sourceFinder  = new ObjectMembersMappingSourceFinder(new AnnotatedType(source.Type), generator.IdentifierName(source.Name), generator);
            var targets       = MappingTargetHelper.GetFieldsThaCanBeSetPrivately(methodSymbol.ContainingType, mappingContext);

            return(mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext));
        }
        public IEnumerable <SyntaxNode> GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel)
        {
            var mappingEngine = new MappingEngine(semanticModel, generator, methodSymbol.ContainingAssembly);
            var source        = methodSymbol.Parameters[0];
            var target        = methodSymbol.Parameters[1];
            var targets       = ObjectHelper.GetFieldsThaCanBeSetPublicly(target.Type, methodSymbol.ContainingAssembly);
            var sourceFinder  = new ObjectMembersMappingSourceFinder(source.Type, generator.IdentifierName(source.Name), generator);

            return(mappingEngine.MapUsingSimpleAssignment(generator, targets, sourceFinder, globalTargetAccessor: generator.IdentifierName(target.Name)));
        }
        public async Task <IReadOnlyList <SyntaxNode> > GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator,
                                                                               SemanticModel semanticModel, MappingContext mappingContext)
        {
            var mappingEngine       = new MappingEngine(semanticModel, generator);
            var source              = methodSymbol.Parameters[0];
            var target              = methodSymbol.Parameters[1];
            var mappingTargetHelper = new MappingTargetHelper();
            var targets             = mappingTargetHelper.GetFieldsThaCanBeSetPublicly(target.Type, mappingContext);
            var sourceFinder        = new ObjectMembersMappingSourceFinder(new AnnotatedType(source.Type), generator.IdentifierName(source.Name));

            return(await mappingEngine.MapUsingSimpleAssignment(targets, new SingleSourceMatcher(sourceFinder), mappingContext, globalTargetAccessor : generator.IdentifierName(target.Name)).ConfigureAwait(false));
        }
Esempio n. 8
0
        private static async Task <Document> ReplaceWithMappingBody(Document document, LambdaExpressionSyntax lambda, SemanticModel semanticModel, IMappingMatcher mappingMatcher, CancellationToken cancellationToken)
        {
            var methodSymbol        = (IMethodSymbol)semanticModel.GetSymbolInfo(lambda, cancellationToken).Symbol;
            var createdObjectType   = methodSymbol.Parameters.First().Type;
            var syntaxGenerator     = SyntaxGenerator.GetGenerator(document);
            var mappingEngine       = new MappingEngine(semanticModel, syntaxGenerator);
            var mappingContext      = new MappingContext(lambda, semanticModel);
            var mappingTargetHelper = new MappingTargetHelper();
            var propertiesToSet     = mappingTargetHelper.GetFieldsThaCanBeSetPublicly(createdObjectType, mappingContext);
            var mappings            = await mappingEngine.MapUsingSimpleAssignment(propertiesToSet, mappingMatcher, mappingContext, globalTargetAccessor : SyntaxFactory.IdentifierName(GetParameterIdentifier(lambda))).ConfigureAwait(false);

            var statements = mappings.Select(x => x.AsStatement().WithTrailingTrivia(SyntaxFactory.EndOfLine("\r\n")));

            var newLambda = UpdateLambdaBody(lambda, SyntaxFactory.Block(statements)).WithAdditionalAnnotations(Formatter.Annotation);

            return(await document.ReplaceNodes(lambda, newLambda, cancellationToken).ConfigureAwait(false));
        }