diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ReferenceTypeAttribute.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ReferenceTypeAttribute.cs new file mode 100644 index 000000000000..f9f07473014b --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ReferenceTypeAttribute.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.ResourceManager.Core +{ + /// + /// An attribute class indicating a reference type for code generation. + /// + [AttributeUsage(AttributeTargets.Class)] + public class ReferenceTypeAttribute : Attribute + { + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs index 86a35ac05cf7..7d0537353dca 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs @@ -8,6 +8,7 @@ namespace Azure.ResourceManager.Core /// /// A class representing the base resource used by all azure resources. /// + [ReferenceType] public abstract class Resource : IEquatable, IEquatable, IComparable, IComparable { diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs index 425024c411ac..62b71bc4907b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs @@ -66,7 +66,7 @@ public ResourceType Parent /// /// Implicit operator for initializing a instance from a string. /// - /// String to be conferted into a object. + /// String to be converted into a object. public static implicit operator ResourceType(string other) { if (other is null) @@ -75,6 +75,18 @@ public static implicit operator ResourceType(string other) return new ResourceType(other); } + /// + /// Implicit operator for initializing a string instance from a ResourceType. + /// + /// to be converted into a string object. + public static implicit operator string(ResourceType other) + { + if (other is null) + return null; + + return other.ToString(); + } + /// /// Compares a object with a . /// @@ -175,7 +187,7 @@ public int CompareTo(ResourceType other) int compareResult = 0; if ((compareResult = string.Compare(Namespace, other.Namespace, StringComparison.InvariantCultureIgnoreCase)) == 0 && (compareResult = string.Compare(Type, other.Type, StringComparison.InvariantCultureIgnoreCase)) == 0 && - (other.Parent != null)) + (!(other.Parent is null))) { return Parent.CompareTo(other.Parent); } @@ -236,7 +248,7 @@ public override bool Equals(object obj) var resourceObj = obj as ResourceType; - if (resourceObj != null) + if (!(resourceObj is null)) return Equals(resourceObj); var stringObj = obj as string; @@ -311,7 +323,7 @@ private void Parse(string resourceIdOrType) throw new ArgumentOutOfRangeException(nameof(resourceIdOrType)); } Namespace = parts[1]; - + Type = string.Join("/", parts.Skip(2).Take(parts.Count - 3)); } // Handle resource types (Micsrsoft.Compute/virtualMachines, Microsoft.Network/virtualNetworks/subnets) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TrackedResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TrackedResource.cs index 29a7d114752b..a8639060c3bf 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TrackedResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/TrackedResource.cs @@ -9,6 +9,7 @@ namespace Azure.ResourceManager.Core /// /// Generic representation of a tracked resource. All tracked resources should extend this class /// + [ReferenceType] public abstract class TrackedResource : Resource { ///