Repository navigation
Isolate C# back-compat parameter renaming from serialization #12164
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
Jorge Rangel (jorgerangel-msft)
merged 6 commits into
main
from
copilot/http-client-csharp-fix-deserialization-issue
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
effed87
Initial plan
Copilot 3752159
fix(csharp): isolate public parameter variables from serialization
Copilot 3f0169d
test(csharp): cover optional enum in back-compat deserialization regr…
Copilot f2028e7
test(csharp): use TestData for back-compat serialization validation
Copilot d534ea0
test(csharp): include JSON writing in back-compat baseline
Copilot 95cde59
fix(csharp): merge main and align public input ownership test
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...onTests/BackCompat_RenamedPropertiesKeepSerializationParameters(Custom)/MockInputModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Sample.Models | ||
| { | ||
| public partial class MockInputModel | ||
| { | ||
| public bool Enabled | ||
| { | ||
| get => IsEnabled; | ||
| set => IsEnabled = value; | ||
| } | ||
|
|
||
| public DestinationKind Type | ||
| { | ||
| get => DestinationType; | ||
| set => DestinationType = value; | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...Tests/BackCompat_RenamedPropertiesKeepSerializationParameters(Previous)/MockInputModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Sample.Models | ||
| { | ||
| public partial class MockInputModel | ||
| { | ||
| public MockInputModel(bool enabled, DestinationKind type) | ||
| { | ||
| IsEnabled = enabled; | ||
| DestinationType = type; | ||
| } | ||
|
|
||
| internal MockInputModel(bool enabled, DestinationKind type, DestinationKind? enforcement, IDictionary<string, BinaryData> additionalBinaryDataProperties) | ||
| { | ||
| IsEnabled = enabled; | ||
| DestinationType = type; | ||
| Enforcement = enforcement; | ||
| } | ||
|
|
||
| public bool IsEnabled { get; set; } | ||
| public bool Enabled | ||
| { | ||
| get => IsEnabled; | ||
| set => IsEnabled = value; | ||
| } | ||
|
|
||
| public DestinationKind DestinationType { get; set; } | ||
| public DestinationKind? Enforcement { get; set; } | ||
| public DestinationKind Type | ||
| { | ||
| get => DestinationType; | ||
| set => DestinationType = value; | ||
| } | ||
| } | ||
|
|
||
| public enum DestinationKind | ||
| { | ||
| VirtualNetwork | ||
| } | ||
| } |
87 changes: 87 additions & 0 deletions
87
...erializationCustomizationTests/BackCompat_RenamedPropertiesKeepSerializationParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using Sample.Models; | ||
|
|
||
| namespace Sample | ||
| { | ||
| public partial class MockInputModel | ||
| { | ||
| protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWriter writer, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) | ||
| { | ||
| string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel<global::Sample.Models.MockInputModel>)this).GetFormatFromOptions(options) : options.Format; | ||
| if ((format != "J")) | ||
| { | ||
| throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format."); | ||
| } | ||
| writer.WritePropertyName("enabled"u8); | ||
| writer.WriteBooleanValue(IsEnabled); | ||
| writer.WritePropertyName("type"u8); | ||
| writer.WriteStringValue(DestinationType.ToSerialString()); | ||
| if (global::Sample.Optional.IsDefined(Enforcement)) | ||
| { | ||
| writer.WritePropertyName("enforcement"u8); | ||
| writer.WriteStringValue(Enforcement.Value.ToSerialString()); | ||
| } | ||
| if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) | ||
| { | ||
| foreach (var item in _additionalBinaryDataProperties) | ||
| { | ||
| writer.WritePropertyName(item.Key); | ||
| #if NET6_0_OR_GREATER | ||
| writer.WriteRawValue(item.Value); | ||
| #else | ||
| using (global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(item.Value)) | ||
| { | ||
| global::System.Text.Json.JsonSerializer.Serialize(writer, document.RootElement); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal static global::Sample.Models.MockInputModel DeserializeMockInputModel(global::System.Text.Json.JsonElement element, global::System.ClientModel.Primitives.ModelReaderWriterOptions options) | ||
|
jorgerangel-msft marked this conversation as resolved.
|
||
| { | ||
| if ((element.ValueKind == global::System.Text.Json.JsonValueKind.Null)) | ||
| { | ||
| return null; | ||
| } | ||
| bool isEnabled = default; | ||
| global::Sample.Models.DestinationKind destinationType = default; | ||
| global::Sample.Models.DestinationKind? enforcement = default; | ||
| global::System.Collections.Generic.IDictionary<string, global::System.BinaryData> additionalBinaryDataProperties = new global::Sample.ChangeTrackingDictionary<string, global::System.BinaryData>(); | ||
| foreach (var prop in element.EnumerateObject()) | ||
| { | ||
| if (prop.NameEquals("enabled"u8)) | ||
| { | ||
| isEnabled = prop.Value.GetBoolean(); | ||
| continue; | ||
| } | ||
| if (prop.NameEquals("type"u8)) | ||
| { | ||
| destinationType = prop.Value.GetString().ToDestinationKind(); | ||
| continue; | ||
| } | ||
| if (prop.NameEquals("enforcement"u8)) | ||
| { | ||
| if ((prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.Null)) | ||
| { | ||
| continue; | ||
| } | ||
| enforcement = prop.Value.GetString().ToDestinationKind(); | ||
| continue; | ||
| } | ||
| if ((options.Format != "W")) | ||
| { | ||
| additionalBinaryDataProperties.Add(prop.Name, prop.Value.GetUtf8Bytes()); | ||
| } | ||
| } | ||
| return new global::Sample.Models.MockInputModel(isEnabled, destinationType, enforcement, additionalBinaryDataProperties); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.