private static async Task <(MappingEngine, SemanticModel)> CreateMappingEngine(Document document, SyntaxNode node, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken);

            var mappingEngine = await MappingEngine.Create(document, cancellationToken);

            return(mappingEngine, semanticModel);
        }
        private static async Task <(MappingEngine, SemanticModel)> CreateMappingEngine(Document document, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var mappingEngine = await MappingEngine.Create(document, cancellationToken).ConfigureAwait(false);

            return(mappingEngine, semanticModel);
        }
Exemplo n.º 3
0
        private static async Task <MappingEngine> CreateMappingEngine(Document document, SyntaxNode node,
                                                                      CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken);

            var contextAssembly = semanticModel.FindContextAssembly(node);
            var mappingEngine   = await MappingEngine.Create(document, cancellationToken, contextAssembly);

            return(mappingEngine);
        }
 private static async Task<Document> ReplaceEmptyInitializationBlock(Document document,
     InitializerExpressionSyntax objectInitializer, SemanticModel semanticModel,
     IMappingMatcher mappingMatcher, CancellationToken cancellationToken)
 {
     var oldObjCreation = objectInitializer.FindContainer<ObjectCreationExpressionSyntax>();
     var createdObjectType = ModelExtensions.GetTypeInfo(semanticModel, oldObjCreation).Type;
     var mappingEngine = await MappingEngine.Create(document, cancellationToken);
     
     var newObjectCreation = mappingEngine.AddInitializerWithMapping(oldObjCreation, mappingMatcher, createdObjectType, new MappingContext(objectInitializer, semanticModel ));
     return await document.ReplaceNodes(oldObjCreation, newObjectCreation, cancellationToken);
 }
Exemplo n.º 5
0
        private static async Task <Document> ReplaceWithMappingBody(Document document, LambdaExpressionSyntax lambda, SemanticModel semanticModel, IMappingMatcher mappingMatcher, CancellationToken cancellationToken)
        {
            var methodSymbol      = (IMethodSymbol)semanticModel.GetSymbolInfo(lambda).Symbol;
            var createdObjectType = methodSymbol.Parameters.First().Type;
            var mappingEngine     = await MappingEngine.Create(document, cancellationToken);

            var mappingContext  = new MappingContext(lambda, semanticModel);
            var propertiesToSet = MappingTargetHelper.GetFieldsThaCanBeSetPublicly(createdObjectType, mappingContext);
            var statements      = mappingEngine.MapUsingSimpleAssignment(propertiesToSet, mappingMatcher, mappingContext, globalTargetAccessor: SyntaxFactory.IdentifierName(GetParameterIdentifier(lambda)))
                                  .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));
        }