From 562d1818480edc90143bae9c7d98622c9c6d4d5a Mon Sep 17 00:00:00 2001
From: m-nash <64171366+m-nash@users.noreply.github.com>
Date: Fri, 30 Jul 2021 00:12:22 -0700
Subject: [PATCH] update internal files to work with autorest (#22972)
* combine extension classes
* updates to more comments
* make autorest attributes internal
* update api
* update based on pr feedback
* update internal types to work with autorest
* updates after merge
---
common/ManagementCoreShared/ClientContext.cs | 2 +
.../ReferenceTypeAttribute.cs | 35 ------------
.../ManagementCoreShared/SharedExtensions.cs | 55 ++-----------------
.../Azure.ResourceManager.netstandard2.0.cs | 4 ++
.../src/Azure.ResourceManager.csproj | 2 +-
.../InitializationConstructorAttribute.cs | 6 --
.../PropertyReferenceTypeAttribute.cs | 4 +-
.../src/Internal/ReferenceTypeAttribute.cs | 15 +++++
.../SerializationConstructorAttribute.cs | 6 --
.../src/ResourceManagerExtensions.cs | 53 ++++++++++++++++++
10 files changed, 81 insertions(+), 101 deletions(-)
delete mode 100644 common/ManagementCoreShared/ReferenceTypeAttribute.cs
rename {common/ManagementCoreShared => sdk/resourcemanager/Azure.ResourceManager/src/Internal}/InitializationConstructorAttribute.cs (68%)
rename {common/ManagementCoreShared => sdk/resourcemanager/Azure.ResourceManager/src/Internal}/PropertyReferenceTypeAttribute.cs (91%)
create mode 100644 sdk/resourcemanager/Azure.ResourceManager/src/Internal/ReferenceTypeAttribute.cs
rename {common/ManagementCoreShared => sdk/resourcemanager/Azure.ResourceManager/src/Internal}/SerializationConstructorAttribute.cs (68%)
diff --git a/common/ManagementCoreShared/ClientContext.cs b/common/ManagementCoreShared/ClientContext.cs
index cbea847eea802..dfa7e492ad9aa 100644
--- a/common/ManagementCoreShared/ClientContext.cs
+++ b/common/ManagementCoreShared/ClientContext.cs
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+#nullable enable
+
using System;
using Azure.Core;
using Azure.Core.Pipeline;
diff --git a/common/ManagementCoreShared/ReferenceTypeAttribute.cs b/common/ManagementCoreShared/ReferenceTypeAttribute.cs
deleted file mode 100644
index e9dfa983db037..0000000000000
--- a/common/ManagementCoreShared/ReferenceTypeAttribute.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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)]
- internal class ReferenceTypeAttribute : Attribute
- {
- ///
- /// Instatiate a new reference type attribute.
- ///
- /// The generic type for this reference type.
- public ReferenceTypeAttribute(Type genericType)
- {
- GenericType = genericType;
- }
-
- ///
- /// Instatiate a new reference type attribute.
- ///
- public ReferenceTypeAttribute() : this(null)
- {
- }
-
- ///
- /// Get the generic type for this reference type.
- ///
- public Type GenericType { get; }
- }
-}
diff --git a/common/ManagementCoreShared/SharedExtensions.cs b/common/ManagementCoreShared/SharedExtensions.cs
index a231e9c6bcedc..bddf8db01254e 100644
--- a/common/ManagementCoreShared/SharedExtensions.cs
+++ b/common/ManagementCoreShared/SharedExtensions.cs
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Threading;
@@ -13,35 +15,6 @@ namespace Azure.ResourceManager.Core
///
internal static class SharedExtensions
{
- ///
- /// Add a provider resource to an existing resource id.
- ///
- /// The id to append to.
- /// The provider namespace of the added resource.
- /// The simple type of the added resource, without slashes (/),
- /// for example, 'virtualMachines'.
- /// The name of the resource.
- /// The combined resource id.
- public static ResourceIdentifier AppendProviderResource(this ResourceIdentifier identifier, string providerNamespace, string resourceType, string resourceName)
- {
- ValidateProviderResourceParameters(providerNamespace, resourceType, resourceName);
- return new ResourceIdentifier(identifier, providerNamespace, resourceType, resourceName);
- }
-
- ///
- /// Add a provider resource to an existing resource id.
- ///
- /// The id to append to.
- /// The simple type of the child resource, without slashes (/),
- /// for example, 'subnets'.
- /// The name of the resource.
- /// The combined resource id.
- public static ResourceIdentifier AppendChildResource(this ResourceIdentifier identifier, string childResourceType, string childResourceName)
- {
- ValidateChildResourceParameters(childResourceType, childResourceName);
- return new ResourceIdentifier(identifier, childResourceType, childResourceName);
- }
-
///
/// An extension method for supporting replacing one dictionary content with another one.
/// This is used to support resource tags.
@@ -70,10 +43,11 @@ public static List Trim(this List list, int numberToTrim)
return list;
}
- public static async Task FirstOrDefaultAsync(
+ public static async Task FirstOrDefaultAsync(
this AsyncPageable source,
Func predicate,
CancellationToken token = default)
+ where TSource : notnull
{
if (source == null)
throw new ArgumentNullException(nameof(source));
@@ -94,26 +68,5 @@ public static async Task FirstOrDefaultAsync(
return default;
}
-
- private static void ValidateProviderResourceParameters(string providerNamespace, string resourceType, string resourceName)
- {
- ValidatePathSegment(providerNamespace, nameof(providerNamespace));
- ValidatePathSegment(resourceType, nameof(resourceType));
- ValidatePathSegment(resourceName, nameof(resourceName));
- }
-
- private static void ValidateChildResourceParameters(string childResourceType, string childResourceName)
- {
- ValidatePathSegment(childResourceType, nameof(childResourceType));
- ValidatePathSegment(childResourceName, nameof(childResourceName));
- }
-
- private static void ValidatePathSegment(string segment, string parameterName)
- {
- if (string.IsNullOrWhiteSpace(segment))
- throw new ArgumentNullException(parameterName);
- if (segment.Contains("/"))
- throw new ArgumentOutOfRangeException(parameterName, $"{parameterName} must be a single path segment");
- }
}
}
diff --git a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs
index f793e83f8fc95..467e806a95742 100644
--- a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs
@@ -180,6 +180,10 @@ public static partial class ResourceListOperations
}
public static partial class ResourceManagerExtensions
{
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
+ public static Azure.ResourceManager.ResourceIdentifier AppendChildResource(this Azure.ResourceManager.ResourceIdentifier identifier, string childResourceType, string childResourceName) { throw null; }
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
+ public static Azure.ResourceManager.ResourceIdentifier AppendProviderResource(this Azure.ResourceManager.ResourceIdentifier identifier, string providerNamespace, string resourceType, string resourceName) { throw null; }
public static string GetCorrelationId(this Azure.Response response) { throw null; }
public static Azure.Response WaitForCompletion(this Azure.Operation operation, System.Threading.CancellationToken cancellationToken) { throw null; }
public static Azure.Response WaitForCompletion(this Azure.Operation operation, System.TimeSpan pollingInterval, System.Threading.CancellationToken cancellationToken) { throw null; }
diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj b/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj
index 6b9d3c1f2a1cb..e3b0f6391037e 100644
--- a/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj
@@ -16,5 +16,5 @@
-
+
diff --git a/common/ManagementCoreShared/InitializationConstructorAttribute.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/InitializationConstructorAttribute.cs
similarity index 68%
rename from common/ManagementCoreShared/InitializationConstructorAttribute.cs
rename to sdk/resourcemanager/Azure.ResourceManager/src/Internal/InitializationConstructorAttribute.cs
index 1905165171805..ca2a8246e1213 100644
--- a/common/ManagementCoreShared/InitializationConstructorAttribute.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/InitializationConstructorAttribute.cs
@@ -11,11 +11,5 @@ namespace Azure.ResourceManager.Core
[AttributeUsage(AttributeTargets.Constructor)]
internal class InitializationConstructorAttribute : Attribute
{
- ///
- /// Instatiate a new InitializationConstructor attribute.
- ///
- public InitializationConstructorAttribute()
- {
- }
}
}
diff --git a/common/ManagementCoreShared/PropertyReferenceTypeAttribute.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/PropertyReferenceTypeAttribute.cs
similarity index 91%
rename from common/ManagementCoreShared/PropertyReferenceTypeAttribute.cs
rename to sdk/resourcemanager/Azure.ResourceManager/src/Internal/PropertyReferenceTypeAttribute.cs
index 8c2f505b10eab..5217699a886ab 100644
--- a/common/ManagementCoreShared/PropertyReferenceTypeAttribute.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/PropertyReferenceTypeAttribute.cs
@@ -2,7 +2,6 @@
// Licensed under the MIT License.
using System;
-using System.Collections.Generic;
namespace Azure.ResourceManager.Core
{
@@ -24,7 +23,8 @@ public PropertyReferenceTypeAttribute(Type[] skipTypes)
///
/// Instatiate a new reference type attribute.
///
- public PropertyReferenceTypeAttribute() : this(null)
+ public PropertyReferenceTypeAttribute()
+ : this(Array.Empty())
{
}
diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Internal/ReferenceTypeAttribute.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/ReferenceTypeAttribute.cs
new file mode 100644
index 0000000000000..3ce60728827d8
--- /dev/null
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/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)]
+ internal class ReferenceTypeAttribute : Attribute
+ {
+ }
+}
diff --git a/common/ManagementCoreShared/SerializationConstructorAttribute.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/SerializationConstructorAttribute.cs
similarity index 68%
rename from common/ManagementCoreShared/SerializationConstructorAttribute.cs
rename to sdk/resourcemanager/Azure.ResourceManager/src/Internal/SerializationConstructorAttribute.cs
index 7d2d548bd0cda..fa633ca4f1a45 100644
--- a/common/ManagementCoreShared/SerializationConstructorAttribute.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/Internal/SerializationConstructorAttribute.cs
@@ -11,11 +11,5 @@ namespace Azure.ResourceManager.Core
[AttributeUsage(AttributeTargets.Constructor)]
internal class SerializationConstructorAttribute : Attribute
{
- ///
- /// Instatiate a new SerializationConstructor attribute.
- ///
- public SerializationConstructorAttribute()
- {
- }
}
}
diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceManagerExtensions.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceManagerExtensions.cs
index 8c61b5f445f6d..42ae8581dde3c 100644
--- a/sdk/resourcemanager/Azure.ResourceManager/src/ResourceManagerExtensions.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager/src/ResourceManagerExtensions.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
+using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
@@ -13,6 +14,37 @@ namespace Azure.ResourceManager.Core
///
public static class ResourceManagerExtensions
{
+ ///
+ /// Add a provider resource to an existing resource id.
+ ///
+ /// The id to append to.
+ /// The provider namespace of the added resource.
+ /// The simple type of the added resource, without slashes (/),
+ /// for example, 'virtualMachines'.
+ /// The name of the resource.
+ /// The combined resource id.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static ResourceIdentifier AppendProviderResource(this ResourceIdentifier identifier, string providerNamespace, string resourceType, string resourceName)
+ {
+ ValidateProviderResourceParameters(providerNamespace, resourceType, resourceName);
+ return new ResourceIdentifier(identifier, providerNamespace, resourceType, resourceName);
+ }
+
+ ///
+ /// Add a provider resource to an existing resource id.
+ ///
+ /// The id to append to.
+ /// The simple type of the child resource, without slashes (/),
+ /// for example, 'subnets'.
+ /// The name of the resource.
+ /// The combined resource id.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static ResourceIdentifier AppendChildResource(this ResourceIdentifier identifier, string childResourceType, string childResourceName)
+ {
+ ValidateChildResourceParameters(childResourceType, childResourceName);
+ return new ResourceIdentifier(identifier, childResourceType, childResourceName);
+ }
+
///
/// Waits for the completion of the long running operations.
///
@@ -86,5 +118,26 @@ public static string GetCorrelationId(this Response response)
response.Headers.TryGetValue("x-ms-correlation-request-id", out correlationId);
return correlationId;
}
+
+ private static void ValidateProviderResourceParameters(string providerNamespace, string resourceType, string resourceName)
+ {
+ ValidatePathSegment(providerNamespace, nameof(providerNamespace));
+ ValidatePathSegment(resourceType, nameof(resourceType));
+ ValidatePathSegment(resourceName, nameof(resourceName));
+ }
+
+ private static void ValidateChildResourceParameters(string childResourceType, string childResourceName)
+ {
+ ValidatePathSegment(childResourceType, nameof(childResourceType));
+ ValidatePathSegment(childResourceName, nameof(childResourceName));
+ }
+
+ private static void ValidatePathSegment(string segment, string parameterName)
+ {
+ if (string.IsNullOrWhiteSpace(segment))
+ throw new ArgumentNullException(parameterName);
+ if (segment.Contains("/"))
+ throw new ArgumentOutOfRangeException(parameterName, $"{parameterName} must be a single path segment");
+ }
}
}