Beispiel #1
0
        private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context)
        {
            var enumDeclaration = (EnumDeclarationSyntax)context.Node;

            FormatEachEnumMemberOnSeparateLineRefactoring.Analyze(context, enumDeclaration);

            RemoveEnumDefaultUnderlyingTypeRefactoring.Analyze(context, enumDeclaration);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out BaseTypeSyntax baseType))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove default underlying type",
                cancellationToken => RemoveEnumDefaultUnderlyingTypeRefactoring.RefactorAsync(context.Document, baseType, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveEnumDefaultUnderlyingType));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            SimpleBaseTypeSyntax baseType = root
                                            .FindNode(context.Span, getInnermostNodeForTie: true)?
                                            .FirstAncestorOrSelf <SimpleBaseTypeSyntax>();

            if (baseType == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove default underlying type",
                cancellationToken => RemoveEnumDefaultUnderlyingTypeRefactoring.RefactorAsync(context.Document, baseType, cancellationToken),
                DiagnosticIdentifiers.RemoveEnumDefaultUnderlyingType + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }