Skip to content

fix(csharp): Fallback init to set #6613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions fern/pages/changelogs/csharp-sdk/2025-03-31.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.15.12
**`(fix):`** Fallback from `init` to `set` on .NET Framework & .NET Standard 2.0 for public and protected properties.
This ensures the properties can be set on older TFMs without compilation errors.


6 changes: 3 additions & 3 deletions generators/csharp/base/src/asIs/FileParameter.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public record FileParameter :
/// <summary>
/// The name of the file to be uploaded.
/// </summary>
public string? FileName { get; init; }
public string? FileName { get; set; }

/// <summary>
/// The content type of the file to be uploaded.
/// </summary>
public string? ContentType { get; init; }
public string? ContentType { get; set; }

/// <summary>
/// The content of the file to be uploaded.
/// </summary>
public required Stream Stream { get; init; }
public required Stream Stream { get; set; }

/// <inheritdoc/>
public void Dispose()
Expand Down
45 changes: 40 additions & 5 deletions generators/csharp/base/src/asIs/GrpcRequestOptions.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,60 @@ public partial class GrpcRequestOptions
/// <summary>
/// The maximum number of retry attempts.
/// </summary>
public int? MaxRetries { get; init; }
public int? MaxRetries {
get;
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
}

/// <summary>
/// The timeout for the request.
/// </summary>
public TimeSpan? Timeout { get; init; }
public TimeSpan? Timeout {
get;
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
}

/// <summary>
/// Options for write operations.
/// </summary>
public WriteOptions? WriteOptions { get; init; }
public WriteOptions? WriteOptions {
get;
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
}

/// <summary>
/// Client-side call credentials. Provide authorization with per-call granularity.
/// </summary>
public CallCredentials? CallCredentials { get; init; }
public CallCredentials? CallCredentials {
get;
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
}

/// <summary>
/// Headers to be sent with this particular request.
/// </summary>
internal Headers Headers { get; init; } = new();
internal Headers Headers {
get;
#if NET5_0_OR_GREATER
init;
#else
set;
#endif
} = new();
}
23 changes: 20 additions & 3 deletions generators/csharp/codegen/src/ast/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,27 @@ export class Field extends AstNode {
writer.write("get; ");
}
if (this.init) {
if (!this.hasSameAccess(this.init)) {
writer.write(`${this.init} `);
// if init is accessible to the end user (public, or protected through inheritance),
// we should not expose init to the user on .NET Framework
const needsFallback =
(this.access === Access.Public || this.access === Access.Protected) &&
(this.init === true || this.init === Access.Public || this.init === Access.Protected);
if (needsFallback) {
writer.writeLine();
writer.writeNoIndent("#if NET5_0_OR_GREATER\n");
if (!this.hasSameAccess(this.init)) {
writer.write(`${this.init} `);
}
writer.writeTextStatement("init");
writer.writeNoIndent("#else\n");
writer.writeTextStatement("set");
writer.writeNoIndent("#endif\n");
} else {
if (!this.hasSameAccess(this.init)) {
writer.write(`${this.init} `);
}
writer.write("init; ");
}
writer.write("init; ");
}
if (this.set) {
if (!this.hasSameAccess(this.set)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export class RootClientGenerator extends FileGenerator<CSharpFile, SdkCustomConf
csharp.field({
access: csharp.Access.Public,
get: true,
init: true,
name: subpackage.name.pascalCase.safeName,
type: csharp.Type.reference(this.context.getSubpackageClassReference(subpackage))
})
Expand Down
9 changes: 9 additions & 0 deletions generators/csharp/sdk/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
# Set `enable-forward-compatible-enums` to `false` in the configuration to generate the old enums.
# irVersion: 53

- version: 1.15.12
createdAt: "2025-03-31"
irVersion: 57
changelogEntry:
- type: fix
summary: |
Fallback from `init` to `set` on .NET Framework & .NET Standard 2.0 for public and protected properties.
This ensures the properties can be set on older TFMs without compilation errors.

- version: 1.15.11
createdAt: "2025-03-25"
irVersion: 57
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading