Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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()));
            }
        }
Esempio n. 3
0
 public PropertyChangedUnnecessaryAllocationRewriter(PropertyChangedEventArgsAnalyzerData contextData, TextSpan diagnosticLocation)
 {
     this.contextData        = contextData;
     this.diagnosticLocation = diagnosticLocation;
 }