ren generic type param

This commit is contained in:
Collin M. Barrett 2019-07-01 15:42:27 -05:00
parent 63b33a20ac
commit 9e9bb5ebfd
2 changed files with 7 additions and 7 deletions

View file

@ -6,6 +6,6 @@ namespace FilterLists.Agent.Core.Interfaces
{
public interface IUrlsRepository
{
Task<IEnumerable<Uri>> GetAllAsync<TEntityUrls>();
Task<IEnumerable<Uri>> GetAllAsync<TModel>();
}
}

View file

@ -18,20 +18,20 @@ public UrlsRepository(IFilterListsApiClient apiClient)
_apiClient = apiClient;
}
public async Task<IEnumerable<Uri>> GetAllAsync<TEntityUrls>()
public async Task<IEnumerable<Uri>> GetAllAsync<TModel>()
{
var endpoint = BuildEndpoint<TEntityUrls>();
var endpoint = BuildEndpoint<TModel>();
var request = new RestRequest(endpoint);
var response = await _apiClient.ExecuteAsync<IEnumerable<TEntityUrls>>(request);
var response = await _apiClient.ExecuteAsync<IEnumerable<TModel>>(request);
return response.SelectMany(r =>
r.GetType().GetProperties().Where(p => p.GetType() == typeof(Uri)).Select(p => (Uri)p.GetValue(r)))
.Where(u => u != null);
}
private static string BuildEndpoint<TEntityUrls>()
private static string BuildEndpoint<TModel>()
{
string endpointSuffix;
switch (typeof(TEntityUrls).Name)
switch (typeof(TModel).Name)
{
case nameof(SyntaxUrls):
endpointSuffix = "es";
@ -44,7 +44,7 @@ private static string BuildEndpoint<TEntityUrls>()
break;
}
return $"{typeof(TEntityUrls).Name.Replace("Urls", endpointSuffix).ToLowerInvariant()}/seed";
return $"{typeof(TModel).Name.Replace("Urls", endpointSuffix).ToLowerInvariant()}/seed";
}
}
}