コード例 #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));
        }
コード例 #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()));
            }
        }
コード例 #3
0
 public PropertyChangedUnnecessaryAllocationRewriter(PropertyChangedEventArgsAnalyzerData contextData, TextSpan diagnosticLocation)
 {
     this.contextData        = contextData;
     this.diagnosticLocation = diagnosticLocation;
 }