Skip to content

Commit

Permalink
fix(csharp): Fix bug where generated ClientOptions.Clone did not comp…
Browse files Browse the repository at this point in the history
…ile (#5018)

* fix(csharp-sdk): Fix bug where generated ClientOptions.Clone did not compile
  • Loading branch information
Swimburger authored Oct 28, 2024
1 parent 9ba609d commit 87c3585
Show file tree
Hide file tree
Showing 208 changed files with 640 additions and 622 deletions.
8 changes: 4 additions & 4 deletions generators/csharp/codegen/src/project/CsharpProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,23 @@ class CsProj {
public toString(): string {
const projectGroup = this.getProjectGroup();
const dependencies = this.getDependencies();
return `
return `
<Project Sdk="Microsoft.NET.Sdk">
${projectGroup.join("\n")}
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'netstandard2.0'">
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Portable.System.DateTimeOnly" Version="8.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="PolySharp" Version="1.14.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
21 changes: 16 additions & 5 deletions generators/csharp/sdk/src/options/ClientOptionsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ClientOptionsGenerator extends FileGenerator<CSharpFile, SdkCustomC
class_.addField(this.getGrpcOptionsField());
}

class_.addMethod(this.getCloneMethod());
class_.addMethod(this.getCloneMethod(class_));

return new CSharpFile({
clazz: class_,
Expand Down Expand Up @@ -152,22 +152,33 @@ export class ClientOptionsGenerator extends FileGenerator<CSharpFile, SdkCustomC
});
}

private getCloneMethod(): csharp.Method {
private getCloneMethod(class_: csharp.Class): csharp.Method {
// TODO: add the GRPC options here eventually
return csharp.method({
access: "internal",
summary: "Clones this and returns a new instance",
name: "Clone",
return_: csharp.Type.reference(this.context.getClientOptionsClassReference()),
body: csharp.codeblock((writer) => {
writer.writeTextStatement(`return new ClientOptions
writer.writeTextStatement(
`return new ClientOptions
{
Environment = Environment,
` +
// TODO: iterate over all public fields and generate the clone logic
// for Headers, we should add a `.Clone` method on it and call that
(class_.getFields().find((field) => field.name === "Environment") !== undefined
? " Environment = Environment,"
: "") +
(class_.getFields().find((field) => field.name === BASE_URL_FIELD_NAME) !== undefined
? ` ${BASE_URL_FIELD_NAME} = ${BASE_URL_FIELD_NAME},`
: "") +
`
HttpClient = HttpClient,
MaxRetries = MaxRetries,
Timeout = Timeout,
Headers = new Headers(new Dictionary<string, HeaderValue>(Headers))
};`);
};`
);
}),
isAsync: false,
parameters: []
Expand Down
7 changes: 7 additions & 0 deletions generators/csharp/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- version: 1.8.2
irVersion: 53
createdAt: "2024-10-28"
changelogEntry:
- type: fix
summary: |
Fixes a bug where the ClientOptions would not compile due to incorrect Clone method generation.
- version: 1.8.1
irVersion: 53
createdAt: "2024-10-08"
Expand Down

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

8 changes: 4 additions & 4 deletions seed/csharp-model/alias/src/SeedAlias/SeedAlias.csproj

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

8 changes: 4 additions & 4 deletions seed/csharp-model/any-auth/src/SeedAnyAuth/SeedAnyAuth.csproj

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.

8 changes: 4 additions & 4 deletions seed/csharp-model/bytes/src/SeedBytes/SeedBytes.csproj

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

0 comments on commit 87c3585

Please sign in to comment.