Skip to content

CA1822, Member can be static, incorrectly firing for instance extension member #81564

@davidwengier

Description

@davidwengier

Version: 18.3.0 Insiders [11305.81.main]

Image

CA1822 reports the member doesn't access instance data and can be marked static, but of course if you do that node is then a compile error because it absolutely can't be static.

Full code, FWIW

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Microsoft.CodeAnalysis.Razor.Workspaces;

internal static class CSharpSyntaxNodeExtensions
{
    extension(SyntaxNode node)
    {
        internal bool IsStringLiteral()
        {
            return node is InterpolatedStringTextSyntax or LiteralExpressionSyntax
            {
                RawKind: (int)SyntaxKind.StringLiteralExpression or (int)SyntaxKind.Utf8StringLiteralExpression
            };
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions