Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.ResourceManager.Core
{
/// <summary>
/// An attribute class indicating a reference type for code generation.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ReferenceTypeAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Azure.ResourceManager.Core
/// <summary>
/// A class representing the base resource used by all azure resources.
/// </summary>
[ReferenceType]
public abstract class Resource : IEquatable<Resource>, IEquatable<string>, IComparable<Resource>,
IComparable<string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResourceType Parent
/// <summary>
/// Implicit operator for initializing a <see cref="ResourceType"/> instance from a string.
/// </summary>
/// <param name="other"> String to be conferted into a <see cref="ResourceType"/> object. </param>
/// <param name="other"> String to be converted into a <see cref="ResourceType"/> object. </param>
public static implicit operator ResourceType(string other)
{
if (other is null)
Expand All @@ -75,6 +75,18 @@ public static implicit operator ResourceType(string other)
return new ResourceType(other);
}

/// <summary>
/// Implicit operator for initializing a string instance from a ResourceType.
/// </summary>
/// <param name="other"> <see cref="ResourceType"/> to be converted into a string object. </param>
public static implicit operator string(ResourceType other)
{
if (other is null)
return null;

return other.ToString();
}

/// <summary>
/// Compares a <see cref="ResourceType"/> object with a <see cref="string"/>.
/// </summary>
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Azure.ResourceManager.Core
/// <summary>
/// Generic representation of a tracked resource. All tracked resources should extend this class
/// </summary>
[ReferenceType]
public abstract class TrackedResource : Resource
{
/// <summary>
Expand Down