diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs
index c48d43adf896..82abccb03c2e 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/ResourceType.cs
@@ -102,6 +102,18 @@ public static implicit operator ResourceType(string other)
return new ResourceType(other);
}
+ ///
+ /// Implicit operator for initializing a string from a .
+ ///
+ /// to be converted into a string.
+ public static implicit operator string(ResourceType other)
+ {
+ if (other is null)
+ return null;
+
+ return other.ToString();
+ }
+
///
/// Compares two objects.
///
diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs
index 9b33b7f6254e..31c4d10ff422 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/ResourceTypeTests.cs
@@ -136,6 +136,15 @@ public void NullImplicitFromString()
Assert.IsNull(to);
}
+ [TestCase]
+ public void NullImplicitTotring()
+ {
+ ResourceType from = null;
+ string to = from;
+
+ Assert.IsNull(to);
+ }
+
[TestCase(false, null, "Microsoft.Network1/VirtualNetworks2/subnets1")]
[TestCase(false, "Microsoft.Network1/VirtualNetworks2/subnets1", null)]
[TestCase(true, null, null)]
@@ -230,5 +239,18 @@ public void EqualsWithObjectString(bool expected, string left, string right)
object rightObject = right;
Assert.AreEqual(expected, rt.Equals(rightObject));
}
+
+ [TestCase("Microsoft.classicStorage/storageAccounts")]
+ [TestCase("Microsoft.ClassicStorage/diffaccount")]
+ [TestCase("Microsoft.ClassicStorage/storageAccounts")]
+ [TestCase(null)]
+ [TestCase("Foo.Bar/puppies")]
+ public void ImplicitToString(string expected)
+ {
+ ResourceType type = expected;
+ string actual = type;
+
+ Assert.AreEqual(expected, actual);
+ }
}
}