private void AnalyzeObjectCreationExpression(SyntaxNodeAnalysisContext context) { var objectCreationExpression = (ObjectCreationExpressionSyntax)context.Node; RemoveEmptyInitializerRefactoring.Analyze(context, objectCreationExpression); AddConstructorArgumentListRefactoring.Analyze(context, objectCreationExpression); RemoveEmptyArgumentListRefactoring.Analyze(context, objectCreationExpression); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out ObjectCreationExpressionSyntax objectCreationExpression)) { return; } CodeAction codeAction = CodeAction.Create( "Add parentheses", cancellationToken => AddConstructorArgumentListRefactoring.RefactorAsync(context.Document, objectCreationExpression, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.AddConstructorArgumentList)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); ObjectCreationExpressionSyntax syntax = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <ObjectCreationExpressionSyntax>(); if (syntax == null) { return; } CodeAction codeAction = CodeAction.Create( "Add parentheses", cancellationToken => AddConstructorArgumentListRefactoring.RefactorAsync(context.Document, syntax, cancellationToken), DiagnosticIdentifiers.AddConstructorArgumentList + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }