private static async Task <Document> ChangePropertyChangedEventArgsToStaticAsync(Document document, Location location, ImmutableDictionary <string, string> properties, CancellationToken cancellationToken) { var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken); var data = PropertyChangedEventArgsAnalyzerData.FromDiagnosticProperties(properties); var newSyntaxRoot = new PropertyChangedUnnecessaryAllocationRewriter(data, location.SourceSpan).Visit(syntaxRoot); return(document.WithSyntaxRoot(newSyntaxRoot)); }
private static void PropertyChangedCreation(SyntaxNodeAnalysisContext context) { var propertyChangedEventArgsCreationExpr = (ObjectCreationExpressionSyntax)context.Node; var identifier = propertyChangedEventArgsCreationExpr.Type.Accept(ExtractIdentifier); if (ShouldReportDiagnostic(propertyChangedEventArgsCreationExpr, identifier.ValueText)) { var data = new PropertyChangedEventArgsAnalyzerData(propertyChangedEventArgsCreationExpr); context.ReportDiagnostic(Diagnostic.Create(Rule, propertyChangedEventArgsCreationExpr.GetLocation(), data.ToDiagnosticProperties())); } }
public PropertyChangedUnnecessaryAllocationRewriter(PropertyChangedEventArgsAnalyzerData contextData, TextSpan diagnosticLocation) { this.contextData = contextData; this.diagnosticLocation = diagnosticLocation; }