public async Task <IReadOnlyList <SyntaxNode> > GenerateImplementation(IMethodSymbol methodSymbol, SyntaxGenerator generator, SemanticModel semanticModel, MappingContext mappingContext) { var mappingEngine = new MappingEngine(semanticModel, generator); var targetType = methodSymbol.ReturnType; var sourceFinder = new LocalScopeMappingSourceFinder(semanticModel, methodSymbol); var objectCreationExpressionSyntax = (ObjectCreationExpressionSyntax)generator.ObjectCreationExpression(targetType.StripNullability()); var newExpression = await mappingEngine.AddInitializerWithMappingAsync(objectCreationExpressionSyntax, new SingleSourceMatcher(sourceFinder), targetType, mappingContext).ConfigureAwait(false); return(new[] { generator.ReturnStatement(newExpression).WithAdditionalAnnotations(Formatter.Annotation) }); }
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 syntaxGenerator = SyntaxGenerator.GetGenerator(document); var mappingEngine = new MappingEngine(semanticModel, syntaxGenerator); var mappingContext = new MappingContext(objectInitializer, semanticModel); var newObjectCreation = await mappingEngine.AddInitializerWithMappingAsync(oldObjCreation, mappingMatcher, createdObjectType, mappingContext).ConfigureAwait(false); return(await document.ReplaceNodes(oldObjCreation, newObjectCreation, cancellationToken).ConfigureAwait(false)); }