Skip to content

Conversation

@radekdoulik
Copy link
Member

To fix this error and improve performance a bit:

error CA1802: Field 'invalidStateMessage' is declared as 'readonly' but is initialized with a constant value. Mark this field as 'const' instead.

Context: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1802

To fix this error and improve performance a bit:

    error CA1802: Field 'invalidStateMessage' is declared as 'readonly' but is initialized with a constant value. Mark this field as 'const' instead.

Context: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1802
@radekdoulik
Copy link
Member Author

OK, looks like it doesn't work with older compilers and even in the new one it fails with:

error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

So we will need to suppress CA1802 instead.

@radekdoulik
Copy link
Member Author

Found a way to avoid both and still gain some performance.

@jonathanpeppers jonathanpeppers merged commit a8f68e5 into dotnet:master Jan 15, 2021
@jpobst jpobst added this to the 11.2 (16.10 / 8.10) milestone Feb 2, 2021
jonpryor pushed a commit that referenced this pull request Mar 9, 2021
Context: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1802

To fix this error and improve performance a bit:

    error CA1802: Field 'invalidStateMessage' is declared as 'readonly' but is initialized with a constant value. Mark this field as 'const' instead.

We can't use an interpolated string, or we get the following error on older compilers:

    error CS8652: The feature 'constant interpolated strings' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

We can just use the `+` operator and `const`.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants