-
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.
- Loading branch information
Yeming Liu
committed
Apr 21, 2021
1 parent
293a1f2
commit e808485
Showing
4 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using Azure.Core; | ||
|
||
namespace Azure.ResourceManager.Core | ||
{ | ||
/// <summary> | ||
/// A class representing a sub-resource that contains only the ID. | ||
/// </summary> | ||
public partial class SubResource : IUtf8JsonSerializable | ||
{ | ||
/// <summary> | ||
/// Serialize the input SubResource object. | ||
/// </summary> | ||
/// <param name="writer"> Input Json writer. </param> | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteStartObject(); | ||
if (Optional.IsDefined(Id)) | ||
{ | ||
writer.WritePropertyName("id"); | ||
writer.WriteStringValue(Id); | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
|
||
/// <summary> | ||
/// Deserialize the input JSON element to a SubResource object. | ||
/// </summary> | ||
/// <param name="element">The JSON element to be deserialized.</param> | ||
/// <returns>Deserialized SubResource object.</returns> | ||
internal static SubResource DeserializeSubResource(JsonElement element) | ||
{ | ||
Optional<string> id = default; | ||
foreach (var property in element.EnumerateObject()) | ||
{ | ||
if (property.NameEquals("id")) | ||
{ | ||
id = property.Value.GetString(); | ||
continue; | ||
} | ||
} | ||
return new SubResource(id.Value); | ||
} | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...urcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.Serialization.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,49 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using Azure.Core; | ||
|
||
namespace Azure.ResourceManager.Core | ||
{ | ||
/// <summary> | ||
/// A class representing a sub-resource that contains only the ID. | ||
/// </summary> | ||
public partial class SubResourceReadOnly : IUtf8JsonSerializable | ||
{ | ||
/// <summary> | ||
/// Serialize the input SubResourceReadOnly object. | ||
/// </summary> | ||
/// <param name="writer"> Input Json writer. </param> | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
/// <summary> | ||
/// Deserialize the input JSON element to a SubResourceReadOnly object. | ||
/// </summary> | ||
/// <param name="element">The JSON element to be deserialized.</param> | ||
/// <returns>Deserialized SubResourceReadOnly object.</returns> | ||
internal static SubResourceReadOnly DeserializeSubResourceReadOnly(JsonElement element) | ||
{ | ||
Optional<string> id = default; | ||
foreach (var property in element.EnumerateObject()) | ||
{ | ||
if (property.NameEquals("id")) | ||
{ | ||
id = property.Value.GetString(); | ||
continue; | ||
} | ||
} | ||
return new SubResourceReadOnly(id.Value); | ||
} | ||
} | ||
} |
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