Skip to content

Commit a8f68e5

Browse files
authored
Use const instead of static readonly (#782)
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`.
1 parent 00862ad commit a8f68e5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Java.Interop/Java.Interop/JniNativeMethodRegistrationArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Java.Interop
77
{
88
public struct JniNativeMethodRegistrationArguments
99
{
10-
static readonly string invalidStateMessage = $"{nameof(JniNativeMethodRegistrationArguments)} state is invalid. Please use constructor with parameters.";
10+
const string invalidStateMessage = nameof(JniNativeMethodRegistrationArguments) + " state is invalid. Please use constructor with parameters.";
1111

1212
public ICollection<JniNativeMethodRegistration> Registrations {
1313
get { return _registrations ?? throw new InvalidOperationException (invalidStateMessage); }

0 commit comments

Comments
 (0)