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 dead code for service expansions #1751

Merged
merged 1 commit into from
Aug 16, 2019
Merged
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
40 changes: 0 additions & 40 deletions src/Stripe.net/Services/_base/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ protected async Task<T> RequestAsync<T>(
CancellationToken cancellationToken = default(CancellationToken))
where T : IStripeEntity
{
options = this.SetupOptions(options, IsStripeList<T>());
requestOptions = this.SetupRequestOptions(requestOptions);
return await this.Client.RequestAsync<T>(
method,
Expand Down Expand Up @@ -287,29 +286,6 @@ protected IEnumerable<T> ListRequestAutoPaging<T>(
}
}

protected BaseOptions SetupOptions(BaseOptions options, bool isListMethod)
{
var serviceExpansions = this.Expansions(isListMethod);
if (!serviceExpansions.Any())
{
return options;
}

options = options ?? new BaseOptions();

if (options.Expand == null)
{
options.Expand = new List<string>();
}

// Compute the union instead of using `AddRangeExpand` to avoid adding duplicate
// values in the list, in case `SetupOptions` has already been called on this options
// instance.
options.Expand = options.Expand.Union(serviceExpansions).ToList();

return options;
}

protected RequestOptions SetupRequestOptions(RequestOptions requestOptions)
{
if (requestOptions == null)
Expand Down Expand Up @@ -345,21 +321,5 @@ private static bool IsStripeList<T>()
return typeInfo.IsGenericType
&& typeInfo.GetGenericTypeDefinition() == typeof(StripeList<>);
}

/// <summary>
/// Returns the list of attributes to expand in requests sent by the service.
/// </summary>
/// <param name="isListMethod">Whether the request is a list request or not.</param>
/// <returns>The list of attributes to expand.</returns>
public List<string> Expansions(bool isListMethod)
{
return this.GetType()
.GetRuntimeProperties()
.Where(p => p.Name.StartsWith("Expand") && p.PropertyType == typeof(bool))
.Where(p => (bool)p.GetValue(this, null))
.Select(p => StringUtils.ToSnakeCase(p.Name.Substring("Expand".Length)))
.Select(i => isListMethod ? $"data.{i}" : i)
.ToList();
}
}
}