diff --git a/PokeApiNet/Models/Common.cs b/PokeApiNet/Models/Common.cs index 49e99df..f96fe0a 100644 --- a/PokeApiNet/Models/Common.cs +++ b/PokeApiNet/Models/Common.cs @@ -41,6 +41,11 @@ public class Language : NamedApiResource /// The name of this resource listed in different languages. /// public List Names { get; set; } + + /// + /// Is endpoint case sensitive + /// + internal new static bool IsApiEndpointCaseSensitive { get; } = true; } /// diff --git a/PokeApiNet/Models/ResourceBase.cs b/PokeApiNet/Models/ResourceBase.cs index 6a8e895..a6ffc46 100644 --- a/PokeApiNet/Models/ResourceBase.cs +++ b/PokeApiNet/Models/ResourceBase.cs @@ -15,6 +15,11 @@ public abstract class ResourceBase /// The endpoint string for this resource /// public static string ApiEndpoint { get; } + + /// + /// Is endpoint case sensitive + /// + public static bool IsApiEndpointCaseSensitive { get; } } /// diff --git a/PokeApiNet/PokeApiClient.cs b/PokeApiNet/PokeApiClient.cs index a4a7e9e..aa2a458 100644 --- a/PokeApiNet/PokeApiClient.cs +++ b/PokeApiNet/PokeApiClient.cs @@ -109,8 +109,9 @@ private static ProductHeaderValue GetDefaultUserAgent() private async Task GetResourcesWithParamsAsync(string apiParam, CancellationToken cancellationToken) where T : ResourceBase { - // lowercase the resource name as the API doesn't recognize upper case and lower case as the same - string sanitizedApiParam = apiParam.ToLowerInvariant(); + // check for case sensitive API endpoint + bool isApiEndpointCaseSensitive = IsApiEndpointCaseSensitive(); + string sanitizedApiParam = isApiEndpointCaseSensitive ? apiParam : apiParam.ToLowerInvariant(); string apiEndpoint = GetApiEndpointString(); return await GetAsync($"{apiEndpoint}/{sanitizedApiParam}/", cancellationToken); @@ -444,5 +445,11 @@ private static string GetApiEndpointString() PropertyInfo propertyInfo = typeof(T).GetProperty("ApiEndpoint", BindingFlags.Static | BindingFlags.NonPublic); return propertyInfo.GetValue(null).ToString(); } + + private static bool IsApiEndpointCaseSensitive() + { + PropertyInfo propertyInfo = typeof(T).GetProperty("IsApiEndpointCaseSensitive", BindingFlags.Static | BindingFlags.NonPublic); + return propertyInfo == null ? false : (bool)propertyInfo.GetValue(null); + } } }