Skip to content

fix(csharp): avoid generating property accessors on const fields with autoImplementedProperties - #2679

Open
alexanderxfgl-bit wants to merge 1 commit into
asyncapi:masterfrom
alexanderxfgl-bit:fix/csharp-const-auto-implemented-properties
Open

alexanderxfgl-bit wants to merge 1 commit into
asyncapi:masterfrom
alexanderxfgl-bit:fix/csharp-const-auto-implemented-properties

Conversation

@alexanderxfgl-bit

Copy link
Copy Markdown

Resolves #2591

Description

When generating C# models for properties declared with const in the schema and with auto-implemented properties enabled, the generator was emitting invalid C# syntax by adding getter property accessors to a const field:

public const string EventType { get; } = "OnEntryStarted";

Since C# consts are fields and cannot have property accessors, this results in compiler errors (e.g. CS0107).

This fix removes the { getter } accessors when rendering const properties, generating standard const fields instead:

public const string EventType = "OnEntryStarted";

Testing

  • Added a new snapshot test should generate a const string with autoImplementedProperties to CSharpGenerator.spec.ts
  • All 9 C# test suites passing (72/72 tests passed)

@netlify

netlify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 7997914
🔍 Latest deploy log https://app.netlify.com/projects/modelina/deploys/6aa3d317a20d2e00095e4b78

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] C#: const properties emit invalid public const T X { get; } = ... with auto-implemented properties

2 participants