Skip to content

Commit

Permalink
Do not generate CS8603 warnings when enabling backing store
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirler committed Apr 19, 2024
1 parent 572155e commit cbcc9ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Changed URI template generation to reuse templates when required templates are absent across operations.
- Updated reserved name providers for Java and Php so that "object" can be escaped.
- Do not generate CS8603 warnings when enabling backing store.

## [1.13.0] - 2024-04-04

Expand Down
6 changes: 4 additions & 2 deletions src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private void WritePropertyInternal(CodeProperty codeElement, LanguageWriter writ
if (codeElement.Parent is not CodeClass parentClass) throw new InvalidOperationException("The parent of a property should be a class");
var backingStoreProperty = parentClass.GetBackingStoreProperty();
var setterAccessModifier = codeElement.ReadOnly && codeElement.Access > AccessModifier.Private ? "private " : string.Empty;
var nullableEx = codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? " ?? throw new InvalidOperationException(\"AdditionalData can not be null\")" : string.Empty;
var nullableOp = !codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? "?" : string.Empty;
var simpleBody = $"get; {setterAccessModifier}set;";
var defaultValue = string.Empty;
switch (codeElement.Kind)
Expand All @@ -52,8 +54,8 @@ private void WritePropertyInternal(CodeProperty codeElement, LanguageWriter writ
var backingStoreKey = codeElement.WireName;
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {propertyType} {codeElement.Name.ToFirstCharacterUpperCase()} {{");
writer.IncreaseIndent();
writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Get<{propertyType}>(\"{backingStoreKey}\"); }}");
writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Set(\"{backingStoreKey}\", value); }}");
writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Get<{propertyType}>(\"{backingStoreKey}\"){nullableEx}; }}");
writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Set(\"{backingStoreKey}\", value); }}");
writer.DecreaseIndent();
writer.WriteLine("}");
break;
Expand Down

0 comments on commit cbcc9ee

Please sign in to comment.