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 need to copy policies #22280

Merged
merged 1 commit into from
Jun 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private ArmClient(
Credential = credential;
BaseUri = baseUri ?? new Uri(DefaultUri);
ClientOptions = options?.Clone() ?? new ArmClientOptions();
Pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions);
Pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, options ?? ClientOptions);

DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId)
? GetDefaultSubscription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using Azure.Core;
using Azure.Core.Pipeline;

namespace Azure.ResourceManager.Core
{
Expand Down Expand Up @@ -60,8 +57,6 @@ public T Convert<T>()
var newOptions = new T();
newOptions.Transport = Transport;

CopyPolicies(this, newOptions);

return newOptions;
}

Expand All @@ -80,31 +75,10 @@ public object GetOverrideObject<T>(Func<object> objectConstructor)
return _overrides.GetOrAdd(typeof(T), objectConstructor());
}

private static void CopyPolicies(ClientOptions source, ClientOptions dest)
{
var perCallPoliciesProperty = source.GetType().GetProperty("PerCallPolicies", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
var perCallPolicies = perCallPoliciesProperty.GetValue(source) as IList<HttpPipelinePolicy>;

foreach (var policy in perCallPolicies)
{
dest.AddPolicy(policy, HttpPipelinePosition.PerCall);
}

var perRetryPoliciesProperty = source.GetType().GetProperty("PerRetryPolicies", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
var perRetryPolicies = perRetryPoliciesProperty.GetValue(source) as IList<HttpPipelinePolicy>;

foreach (var policy in perRetryPolicies)
{
dest.AddPolicy(policy, HttpPipelinePosition.PerRetry);
}
}

internal ArmClientOptions Clone()
{
ArmClientOptions copy = new ArmClientOptions(DefaultLocation);

CopyPolicies(this, copy);

copy.ApiVersions = ApiVersions.Clone();
copy.Transport = Transport;
return copy;
Expand Down