Skip to content
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

remove the different types of resourceIdentifier #22862

Merged
merged 3 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/resourcemanager/Azure.ResourceManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can usually tell by the id string itself which type it is, but if you are un
```C# Snippet:Readme_CastToSpecificType
string resourceId = "/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet";
// We know the subnet is a resource group level identifier since it has a resource group name in its string
ResourceGroupResourceIdentifier id = resourceId;
ResourceIdentifier id = resourceId;
Console.WriteLine($"Subscription: {id.SubscriptionId}");
Console.WriteLine($"ResourceGroup: {id.ResourceGroupName}");
Console.WriteLine($"Vnet: {id.Parent.Name}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public virtual TenantContainer GetTenants()
/// </summary>
/// <param name="id"> The id of the resourcegroup </param>
/// <returns> Resource operations of the resource. </returns>
public virtual ResourceGroupOperations GetResourceGroupOperations(ResourceGroupResourceIdentifier id)
public virtual ResourceGroupOperations GetResourceGroupOperations(string id)
{
return new ResourceGroupOperations(new SubscriptionOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id.SubscriptionId), id.ResourceGroupName);
return new ResourceGroupOperations(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), id);
}

private Subscription GetDefaultSubscription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ namespace Azure.ResourceManager.Resources.Models
/// <summary>
/// A class representing the base resource used by all azure resources.
/// </summary>
[ReferenceType(typeof(TenantResourceIdentifier))]
public abstract class Resource<TIdentifier>
where TIdentifier : TenantResourceIdentifier
[ReferenceType]
public abstract class Resource
{
/// <summary>
/// Initializes an empty instance of <see cref="Resource{TIdentifier}"/>.
/// Initializes an empty instance of <see cref="Resource"/>.
/// </summary>
[InitializationConstructor]
protected Resource() { }

/// <summary>
/// Initializes a new instance of <see cref="Resource{TIdentifier}"/> for deserialization.
/// Initializes a new instance of <see cref="Resource"/> for deserialization.
/// </summary>
/// <param name="id"> The id of the resource. </param>
/// <param name="name"> The name of the resource. </param>
/// <param name="type"> The <see cref="ResourceType"/> of the resource. </param>
[SerializationConstructor]
protected internal Resource(TIdentifier id, string name, ResourceType type)
protected internal Resource(ResourceIdentifier id, string name, ResourceType type)
{
Id = id;
Name = name;
Expand All @@ -35,7 +34,7 @@ protected internal Resource(TIdentifier id, string name, ResourceType type)
/// <summary>
/// Gets or sets the resource identifier.
/// </summary>
public virtual TIdentifier Id { get; }
public virtual ResourceIdentifier Id { get; }

/// <summary>
/// Gets the name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal static ResourceIdentity DeserializeResourceIdentity(JsonElement element
}

Optional<SystemAssignedIdentity> systemAssignedIdentity = default;
IDictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity> userAssignedIdentities = new Dictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity>();
IDictionary<ResourceIdentifier, UserAssignedIdentity> userAssignedIdentities = new Dictionary<ResourceIdentifier, UserAssignedIdentity>();
string type = string.Empty;
foreach (var property in element.EnumerateObject())
{
Expand All @@ -108,7 +108,7 @@ internal static ResourceIdentity DeserializeResourceIdentity(JsonElement element
{
resourceId = keyValuePair.Name;
var userAssignedIdentity = UserAssignedIdentity.DeserializeUserAssignedIdentity(keyValuePair.Value);
userAssignedIdentities.Add(new ResourceGroupResourceIdentifier(resourceId), userAssignedIdentity);
userAssignedIdentities.Add(new ResourceIdentifier(resourceId), userAssignedIdentity);
}

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public ResourceIdentity()
/// </summary>
/// <param name="user"> Dictionary with a <see cref="ResourceIdentifier"/> key and a <see cref="UserAssignedIdentity"/> object value. </param>
/// <param name="useSystemAssigned"> Flag for using <see cref="SystemAssignedIdentity"/> or not. </param>
public ResourceIdentity(Dictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity> user, bool useSystemAssigned)
public ResourceIdentity(Dictionary<ResourceIdentifier, UserAssignedIdentity> user, bool useSystemAssigned)
{
// check for combination of user and system on the impact to type value
SystemAssignedIdentity = useSystemAssigned ? new SystemAssignedIdentity() : null;
UserAssignedIdentities = new Dictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity>();
UserAssignedIdentities = new Dictionary<ResourceIdentifier, UserAssignedIdentity>();
if (user != null)
{
foreach (KeyValuePair<ResourceGroupResourceIdentifier, UserAssignedIdentity> id in user)
foreach (KeyValuePair<ResourceIdentifier, UserAssignedIdentity> id in user)
{
UserAssignedIdentities.Add(id.Key, id.Value);
}
Expand All @@ -48,13 +48,13 @@ public ResourceIdentity(Dictionary<ResourceGroupResourceIdentifier, UserAssigned
/// <param name="systemAssigned"> The <see cref="SystemAssignedIdentity"/> to use. </param>
/// <param name="user"> Dictionary with a <see cref="ResourceIdentifier"/> key and a <see cref="UserAssignedIdentity"/> object value. </param>
[SerializationConstructor]
internal ResourceIdentity(SystemAssignedIdentity systemAssigned, IDictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity> user)
internal ResourceIdentity(SystemAssignedIdentity systemAssigned, IDictionary<ResourceIdentifier, UserAssignedIdentity> user)
{
// TODO: remove this constructor later
SystemAssignedIdentity = systemAssigned;
if (user == null)
{
UserAssignedIdentities = new Dictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity>();
UserAssignedIdentities = new Dictionary<ResourceIdentifier, UserAssignedIdentity>();
}
else
{
Expand All @@ -70,7 +70,7 @@ internal ResourceIdentity(SystemAssignedIdentity systemAssigned, IDictionary<Res
/// <summary>
/// Gets a dictionary of the User Assigned Identities.
/// </summary>
public IDictionary<ResourceGroupResourceIdentifier, UserAssignedIdentity> UserAssignedIdentities { get; private set; }
public IDictionary<ResourceIdentifier, UserAssignedIdentity> UserAssignedIdentities { get; private set; }

/// <summary>
/// Detects if this Identity is equals to another Identity instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Azure.ResourceManager.Resources.Models
/// <summary>
/// A class representing a sub-resource that contains only the ID.
/// </summary>
public partial class SubResource<TIdentifier> : IUtf8JsonSerializable
public partial class SubResource : IUtf8JsonSerializable
{
/// <summary>
/// Serialize the input SubResource object.
Expand All @@ -37,7 +37,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
/// </summary>
/// <param name="element">The JSON element to be deserialized.</param>
/// <returns>Deserialized SubResource object.</returns>
internal static SubResource<TIdentifier> DeserializeSubResource(JsonElement element)
internal static SubResource DeserializeSubResource(JsonElement element)
{
string id = default;
foreach (var property in element.EnumerateObject())
Expand All @@ -48,7 +48,7 @@ internal static SubResource<TIdentifier> DeserializeSubResource(JsonElement elem
continue;
}
}
return new SubResource<TIdentifier>(id);
return new SubResource(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Azure.ResourceManager.Resources.Models
{
/// <summary>
/// A class representing the sub resource of a ResourceIdentifier.
/// A class representing a sub-resource that contains only the read-only ID.
/// </summary>
[ReferenceType]
public class SubResource : SubResource<ResourceIdentifier>
public partial class SubResource
{
/// <summary>
/// Initializes an empty instance of <see cref="SubResource"/> for mocking.
Expand All @@ -22,37 +22,15 @@ protected SubResource()
/// <summary> Initializes a new instance of <see cref="SubResource"/>. </summary>
/// <param name="id"> ARM resource Id. </param>
[SerializationConstructor]
protected internal SubResource(string id) : base(id) { }
}

/// <summary>
/// A class representing a sub-resource that contains only the read-only ID.
/// </summary>
[ReferenceType(typeof(ResourceIdentifier))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")]
public partial class SubResource<TIdentifier>
where TIdentifier : ResourceIdentifier
{
/// <summary>
/// Initializes an empty instance of <see cref="SubResource{TIdentifier}"/> for mocking.
/// </summary>
[InitializationConstructor]
protected SubResource()
{
}

/// <summary> Initializes a new instance of <see cref="SubResource{TIdentifier}"/>. </summary>
/// <param name="id"> ARM resource Id. </param>
[SerializationConstructor]
protected internal SubResource(string id)
{
Id = (TIdentifier)id;
Id = id;
}

/// <summary>
/// Gets the ARM resource identifier.
/// </summary>
/// <value></value>
public virtual TIdentifier Id { get; }
public virtual ResourceIdentifier Id { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Azure.ResourceManager.Resources.Models
/// <summary>
/// Generic representation of a tracked resource. All tracked resources should extend this class
/// </summary>
public abstract partial class TrackedResource<TIdentifier> : IUtf8JsonSerializable
public abstract partial class TrackedResource : IUtf8JsonSerializable
{
/// <summary>
/// Serialize the input TrackedResource object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ namespace Azure.ResourceManager.Resources.Models
/// <summary>
/// Generic representation of a tracked resource. All tracked resources should extend this class
/// </summary>
[ReferenceType(typeof(TenantResourceIdentifier))]
public abstract partial class TrackedResource<TIdentifier> : Resource<TIdentifier>
where TIdentifier : TenantResourceIdentifier
[ReferenceType]
public abstract partial class TrackedResource : Resource
{
/// <summary>
/// Initializes an empty instance of <see cref="TrackedResource{TIdentifier}"/> for mocking.
/// Initializes an empty instance of <see cref="TrackedResource"/> for mocking.
/// </summary>
protected TrackedResource()
{
Tags = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
}

/// <summary>
/// Initializes an empty instance of <see cref="TrackedResource{TIdentifier}"/>.
/// Initializes an empty instance of <see cref="TrackedResource"/>.
/// </summary>
[InitializationConstructor]
protected TrackedResource(Location location)
Expand All @@ -33,15 +32,15 @@ protected TrackedResource(Location location)
}

/// <summary>
/// Initializes a new instance of the <see cref="TrackedResource{TIdentifier}"/> class for deserialization.
/// Initializes a new instance of the <see cref="TrackedResource"/> class for deserialization.
/// </summary>
/// <param name="id"> The id of the resource. </param>
/// <param name="name"> The name of the resource. </param>
/// <param name="type"> The <see cref="ResourceType"/> of the resource. </param>
/// <param name="tags"> The tags for the resource. </param>
/// <param name="location"> The location of the resource. </param>
[SerializationConstructor]
protected internal TrackedResource(TIdentifier id, string name, ResourceType type, Location location, IDictionary<string, string> tags)
protected internal TrackedResource(ResourceIdentifier id, string name, ResourceType type, Location location, IDictionary<string, string> tags)
: base(id, name, type)
{
Tags = tags ?? new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Azure.ResourceManager.Resources.Models
/// <summary>
/// A class representing a sub-resource that contains only the ID.
/// </summary>
public partial class WritableSubResource<TIdentifier> : IUtf8JsonSerializable
public partial class WritableSubResource : IUtf8JsonSerializable
{
/// <summary>
/// Serialize the input WritableSubResource object.
Expand All @@ -37,7 +37,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
/// </summary>
/// <param name="element">The JSON element to be deserialized.</param>
/// <returns>Deserialized WritableSubResource object.</returns>
internal static WritableSubResource<TIdentifier> DeserializeWritableSubResource(JsonElement element)
internal static WritableSubResource DeserializeWritableSubResource(JsonElement element)
{
string id = default;
foreach (var property in element.EnumerateObject())
Expand All @@ -48,7 +48,7 @@ internal static WritableSubResource<TIdentifier> DeserializeWritableSubResource(
continue;
}
}
return new WritableSubResource<TIdentifier>(id);
return new WritableSubResource(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Azure.ResourceManager.Resources.Models
{
/// <summary>
/// A class representing the writable sub resource of a ResourceIdentifier.
/// A class representing a sub-resource that contains only the ID.
/// </summary>
[ReferenceType]
public class WritableSubResource : WritableSubResource<ResourceIdentifier>
public partial class WritableSubResource
{
/// <summary>
/// Initializes an empty instance of <see cref="WritableSubResource"/> for mocking.
Expand All @@ -22,37 +22,15 @@ public WritableSubResource()
/// <summary> Initializes a new instance of <see cref="WritableSubResource"/>. </summary>
/// <param name="id"> ARM resource Id. </param>
[SerializationConstructor]
protected internal WritableSubResource(string id) : base(id) { }
}

/// <summary>
/// A class representing a sub-resource that contains only the ID.
/// </summary>
[ReferenceType(typeof(ResourceIdentifier))]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")]
public partial class WritableSubResource<TIdentifier>
where TIdentifier : ResourceIdentifier
{
/// <summary>
/// Initializes an empty instance of <see cref="WritableSubResource{TIdentifier}"/> for mocking.
/// </summary>
[InitializationConstructor]
public WritableSubResource()
{
}

/// <summary> Initializes a new instance of <see cref="WritableSubResource{TIdentifier}"/>. </summary>
/// <param name="id"> ARM resource Id. </param>
[SerializationConstructor]
protected internal WritableSubResource(string id)
{
Id = (TIdentifier)id;
Id = id;
}

/// <summary>
/// Gets or sets the ARM resource identifier.
/// </summary>
/// <value></value>
public virtual TIdentifier Id { get; set; }
public virtual ResourceIdentifier Id { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ protected PredefinedTagContainer()
/// Initializes a new instance of the <see cref="PredefinedTagContainer"/> class.
/// </summary>
/// <param name="clientContext">Current client context. </param>
/// <param name="subscription">The parent subscription. </param>
internal PredefinedTagContainer(ClientContext clientContext, SubscriptionResourceIdentifier subscription)
: base(clientContext, new SubscriptionResourceIdentifier(subscription))
/// <param name="parentId"> The parent subscription id. </param>
internal PredefinedTagContainer(ClientContext clientContext, ResourceIdentifier parentId)
: base(clientContext, parentId)
{
RestClient = new TagRestOperations(Diagnostics, Pipeline, subscription.SubscriptionId, BaseUri);
RestClient = new TagRestOperations(Diagnostics, Pipeline, parentId.SubscriptionId, BaseUri);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected PredefinedTagOperations()
/// Initializes a new instance of the <see cref="PredefinedTagOperations"/> class.
/// </summary>
/// <param name="clientContext"></param>
/// <param name="subscriptionGuid"> The Guid of the subscription. </param>
internal PredefinedTagOperations(ClientContext clientContext, string subscriptionGuid)
: base(clientContext, new SubscriptionResourceIdentifier(subscriptionGuid))
/// <param name="id"> The id of the subscription. </param>
internal PredefinedTagOperations(ClientContext clientContext, ResourceIdentifier id)
: base(clientContext, id)
{
}

Expand All @@ -40,7 +40,7 @@ internal PredefinedTagOperations(ClientContext clientContext, string subscriptio
/// </summary>
protected override ResourceType ValidResourceType => ResourceType;

private TagRestOperations RestClient => new TagRestOperations(Diagnostics, Pipeline, ((SubscriptionResourceIdentifier)Id).SubscriptionId, BaseUri);
private TagRestOperations RestClient => new TagRestOperations(Diagnostics, Pipeline, Id.SubscriptionId, BaseUri);

/// <summary> This operation allows deleting a value from the list of predefined values for an existing predefined tag name. The value being deleted must not be in use as a tag value for the given tag name for any resource. </summary>
/// <param name="tagName"> The name of the tag. </param>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading