private async Task <Document> GenerateExplicitConversion(Document document, YieldStatementSyntax yieldStatement, CancellationToken cancellationToken) { var mappingEngine = await MappingEngine.Create(document, cancellationToken); var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(yieldStatement.Expression); var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression, returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType); return(await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken)); }
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 async Task <Document> GenerateExplicitConversion(Document document, AssignmentExpressionSyntax assignmentExpression, CancellationToken cancellationToken) { var mappingEngine = await MappingEngine.Create(document, cancellationToken); var sourceType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Right).Type; var destimationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).Type; var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right, sourceType, destimationType); return(await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken)); }
private static async Task <Document> ReplaceEmptyInitializationBlock(Document document, InitializerExpressionSyntax objectInitializer, SemanticModel semanticModel, IMappingSourceFinder mappingSourceFinder, CancellationToken cancellationToken) { var oldObjCreation = objectInitializer.FindContainer <ObjectCreationExpressionSyntax>(); var createdObjectType = ModelExtensions.GetTypeInfo(semanticModel, oldObjCreation).Type; var mappingEngine = await MappingEngine.Create(document, cancellationToken, semanticModel.FindContextAssembly(objectInitializer)); var newObjectCreation = mappingEngine.AddInitializerWithMapping(oldObjCreation, mappingSourceFinder, createdObjectType); return(await document.ReplaceNodes(oldObjCreation, newObjectCreation, cancellationToken)); }