public static void Analyze(SyntaxNodeAnalysisContext context, AssignmentExpressionSyntax assignment) { ExpressionSyntax right = assignment.Right; if (right?.IsKind(SyntaxKind.ObjectCreationExpression) == true) { var objectCreation = (ObjectCreationExpressionSyntax)right; SemanticModel semanticModel = context.SemanticModel; CancellationToken cancellationToken = context.CancellationToken; if (SyntaxAnalyzer.IsEventHandlerOrGenericEventHandler(objectCreation, semanticModel, cancellationToken)) { ArgumentListSyntax argumentList = objectCreation.ArgumentList; if (argumentList != null) { SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments; if (arguments.Count == 1) { ArgumentSyntax argument = arguments.First(); ExpressionSyntax expression = argument.Expression; if (expression != null) { IMethodSymbol methodSymbol = semanticModel.GetMethodSymbol(expression, cancellationToken); if (methodSymbol != null) { ExpressionSyntax left = assignment.Left; if (left?.IsMissing == false && SyntaxAnalyzer.IsEvent(left, semanticModel, cancellationToken) && !objectCreation.SpanContainsDirectives()) { context.ReportDiagnostic(DiagnosticDescriptors.RemoveRedundantDelegateCreation, right.GetLocation()); context.FadeOutToken(DiagnosticDescriptors.RemoveRedundantDelegateCreationFadeOut, objectCreation.NewKeyword); context.FadeOutNode(DiagnosticDescriptors.RemoveRedundantDelegateCreationFadeOut, objectCreation.Type); context.FadeOutParentheses(DiagnosticDescriptors.RemoveRedundantDelegateCreationFadeOut, objectCreation.ArgumentList); } } } } } } } }