-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow camelCase JSON properties to be accessed with PascalCase Dynami…
…cJson property accessors (#34082) * Initial work on JsonData property name casing * pr fb * More expressive casing options; behave as standard Azure SDK model type by default. * Export API * PR fb and implement Set * tidy * Add comments for tricky tests. * Add overload taking casing enum directly * Change default case mapping * update API
- Loading branch information
1 parent
a84139d
commit d64f1db
Showing
9 changed files
with
472 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
29 changes: 29 additions & 0 deletions
29
sdk/core/Azure.Core.Experimental/src/DynamicJsonNameMapping.cs
This file contains 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,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Core.Dynamic | ||
{ | ||
/// <summary> | ||
/// Options for setting new DynamicJson properties. | ||
/// </summary> | ||
public enum DynamicJsonNameMapping | ||
{ | ||
/// <summary> | ||
/// Properties are accessed and written in the JSON buffer with the same casing as the DynamicJson property. | ||
/// </summary> | ||
None = 0, | ||
|
||
/// <summary> | ||
/// A "PascalCase" DynamicJson property can be used to read and set "camelCase" properties that exist in the JSON buffer. | ||
/// New properties are written to the JSON buffer with the same casing as the DynamicJson property. | ||
/// </summary> | ||
PascalCaseGetters = 1, | ||
|
||
/// <summary> | ||
/// Default settings for Azure services. | ||
/// A "PascalCase" DynamicJson property can be used to read and set "camelCase" properties that exist in the JSON buffer. | ||
/// New properties are written to the JSON buffer using "camelCase" property names. | ||
/// </summary> | ||
PascalCaseGettersCamelCaseSetters = 2 | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
sdk/core/Azure.Core.Experimental/src/DynamicJsonOptions.cs
This file contains 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,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Core.Dynamic | ||
{ | ||
/// <summary> | ||
/// Provides the ability for the user to define custom behavior when accessing JSON through a dynamic layer. | ||
/// </summary> | ||
public struct DynamicJsonOptions | ||
{ | ||
/// <summary> | ||
/// Gets the default <see cref="DynamicJsonOptions"/> for Azure services. | ||
/// </summary> | ||
public static readonly DynamicJsonOptions AzureDefault = new() | ||
{ | ||
PropertyNameCasing = DynamicJsonNameMapping.PascalCaseGettersCamelCaseSetters | ||
}; | ||
|
||
/// <summary> | ||
/// Creates a new instance of DynamicJsonOptions. | ||
/// </summary> | ||
public DynamicJsonOptions() { } | ||
|
||
/// <summary> | ||
/// Specifies how properties on <see cref="DynamicJson"/> will be accessed in the underlying JSON buffer. | ||
/// </summary> | ||
public DynamicJsonNameMapping PropertyNameCasing { get; set; } | ||
} | ||
} |
This file contains 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.