-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add a common definition for sub-resource #20524
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
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); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.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,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.ResourceManager.Core | ||
{ | ||
/// <summary> | ||
/// A class representing a sub-resource that contains only the ID. | ||
/// </summary> | ||
[ReferenceType] | ||
public partial class SubResource | ||
{ | ||
/// <summary> Initializes a new instance of SubResource. </summary> | ||
/// <param name="id"> ARM resource Id. </param> | ||
protected internal SubResource(string id) | ||
{ | ||
Id = id; | ||
} | ||
|
||
/// <summary> | ||
/// ARM resource identifier. | ||
/// </summary> | ||
/// <value></value> | ||
public virtual ResourceIdentifier Id { get; set; } | ||
} | ||
} | ||
|
||
// Todo: we want to make the default one (SubResource) to represent read-only data, | ||
// that is the pattern we used in Resource and TrackedResource |
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); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResourceReadOnly.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,25 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.ResourceManager.Core | ||
{ | ||
/// <summary> | ||
/// A class representing a sub-resource that contains only the read-only ID. | ||
/// </summary> | ||
[ReferenceType] | ||
public partial class SubResourceReadOnly | ||
{ | ||
/// <summary> Initializes a new instance of SubResourceReadOnly. </summary> | ||
/// <param name="id"> ARM resource Id. </param> | ||
protected internal SubResourceReadOnly(string id) | ||
{ | ||
Id = id; | ||
} | ||
|
||
/// <summary> | ||
/// ARM resource identifier (read-only). | ||
/// </summary> | ||
/// <value></value> | ||
public virtual ResourceIdentifier Id { get; protected 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,13 +52,13 @@ public int? PlatformFaultDomainCount | |
} | ||
|
||
/// <summary> A list of references to all virtual machines in the availability set. </summary> | ||
public IList<SubResource> VirtualMachines | ||
public IList<Azure.ResourceManager.Compute.Models.SubResource> VirtualMachines | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After introducing the general |
||
{ | ||
get => Model.VirtualMachines; | ||
} | ||
|
||
/// <summary> Specifies information about the proximity placement group that the availability set should be assigned to. <br><br>Minimum api-version: 2018-04-01. </summary> | ||
public SubResource ProximityPlacementGroup | ||
public Azure.ResourceManager.Compute.Models.SubResource ProximityPlacementGroup | ||
{ | ||
get => Model.ProximityPlacementGroup; | ||
set => Model.ProximityPlacementGroup = 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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be get only with a protected constructor that takes in the id and sets it.
This is for deserialization scenarios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a todo in this file for us to consider how to make
SubResource
/SubResourceReadOnly
to follow the current pattern (inResource
andTrackedResource
) that the read-only one should be the default.And I added serilization code. Thanks for the comments!