From 219fb7ca4a45f04d1e89902b3fc6dd6c79a308ef Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 23 Oct 2023 11:32:29 -0400 Subject: [PATCH 1/2] - fixes serialization/deserialization for inheritance in dotnet --- CHANGELOG.md | 1 + src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e61457df..312c2814b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fixed missing imports for method parameters that are query parameters. +- Replaces the use of "new" by "override" and "virtual" in CSharp. - Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354) - Fixed bug where base64url and decimal types would not be generated properly in Java. - Fixed bug where symbol name cleanup would not work on forward single quotes characters [#3426](https://github.com/microsoft/kiota/issues/3426). diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 39724792ba..4cff2235f1 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -599,7 +599,13 @@ private static string GetBaseSuffix(bool isConstructor, bool inherits, CodeClass private void WriteMethodPrototype(CodeMethod code, CodeClass parentClass, LanguageWriter writer, string returnType, bool inherits, bool isVoid) { var staticModifier = code.IsStatic ? "static " : string.Empty; - var hideModifier = inherits && code.IsOfKind(CodeMethodKind.Serializer, CodeMethodKind.Deserializer, CodeMethodKind.Factory) ? "new " : string.Empty; + var hideModifier = (inherits, code.Kind) switch + { + (true, CodeMethodKind.Serializer or CodeMethodKind.Deserializer) => "override ", + (false, CodeMethodKind.Serializer or CodeMethodKind.Deserializer) => "virtual ", + (true, CodeMethodKind.Factory) => "new ", + _ => string.Empty + }; var genericTypePrefix = isVoid ? string.Empty : "<"; var genericTypeSuffix = code.IsAsync && !isVoid ? ">" : string.Empty; var isConstructor = code.IsOfKind(CodeMethodKind.Constructor, CodeMethodKind.ClientConstructor, CodeMethodKind.RawUrlConstructor); From a1ae19ea2833259d1a2492f79b85b9f8d2935614 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 23 Oct 2023 12:22:06 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md Co-authored-by: Caleb Kiage <747955+calebkiage@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 312c2814b5..98b81584ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fixed missing imports for method parameters that are query parameters. -- Replaces the use of "new" by "override" and "virtual" in CSharp. +- Replaces the use of "new" by "override" and "virtual" in CSharp models. - Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354) - Fixed bug where base64url and decimal types would not be generated properly in Java. - Fixed bug where symbol name cleanup would not work on forward single quotes characters [#3426](https://github.com/microsoft/kiota/issues/3426).