Skip to content

Commit 2b1926a

Browse files
authored
Use Polysharp to take advantage of latest language features (#813)
1 parent dbcec6d commit 2b1926a

File tree

22 files changed

+64
-45
lines changed

22 files changed

+64
-45
lines changed

playground/Auth0.NET6/Auth0.NET6.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<IsPackable>false</IsPackable>
6+
<LangVersion>latest</LangVersion>
67
</PropertyGroup>
78

89
<ItemGroup>

playground/Auth0.NETCore3/Auth0.NETCore3.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<IsPackable>false</IsPackable>
6+
<LangVersion>latest</LangVersion>
67
</PropertyGroup>
78

89
<ItemGroup>

playground/Auth0.NETFramework/Auth0.NETFramework.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<NuGetPackageImportStamp>
2626
</NuGetPackageImportStamp>
2727
<IsPackable>false</IsPackable>
28+
<LangVersion>latest</LangVersion>
2829
</PropertyGroup>
2930
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3031
<DebugSymbols>true</DebugSymbols>

src/Auth0.AuthenticationApi/Auth0.AuthenticationApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<AssemblyTitle>Auth0.AuthenticationApi</AssemblyTitle>
55
<AssemblyName>Auth0.AuthenticationApi</AssemblyName>
66
<PackageId>Auth0.AuthenticationApi</PackageId>
7+
<LangVersion>latest</LangVersion>
78
</PropertyGroup>
89
<ItemGroup>
910
<ProjectReference Include="..\Auth0.Core\Auth0.Core.csproj" />

src/Auth0.Core/Auth0.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<AssemblyTitle>Auth0.Core</AssemblyTitle>
55
<AssemblyName>Auth0.Core</AssemblyName>
66
<PackageId>Auth0.Core</PackageId>
7+
<LangVersion>latest</LangVersion>
8+
<WarningsAsErrors>nullable</WarningsAsErrors>
79
</PropertyGroup>
810
<ItemGroup>
911
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

src/Auth0.Core/Exceptions/ApiError.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ public class ApiError
1616
/// Description of the failing HTTP Status Code.
1717
/// </summary>
1818
[JsonProperty("error")]
19-
public string Error { get; set; }
19+
public string? Error { get; set; }
2020

2121
/// <summary>
2222
/// Error code returned by the API.
2323
/// </summary>
2424
[JsonProperty("errorCode")]
25-
public string ErrorCode { get; set; }
25+
public string? ErrorCode { get; set; }
2626

2727
/// <summary>
2828
/// Description of the error.
2929
/// </summary>
3030
[JsonProperty("message")]
31-
public string Message { get; set; }
31+
public string? Message { get; set; }
3232

3333
/// <summary>
3434
/// Additional key/values that might be returned by the error such as `mfa_required`.
@@ -42,7 +42,7 @@ public class ApiError
4242
/// <param name="response"><see cref="HttpResponseMessage"/> to parse.</param>
4343
/// <returns><see cref="Task"/> representing the operation and associated <see cref="ApiError"/> on
4444
/// successful completion.</returns>
45-
public static async Task<ApiError> Parse(HttpResponseMessage response)
45+
public static async Task<ApiError?> Parse(HttpResponseMessage? response)
4646
{
4747
if (response == null || response.Content == null)
4848
return null;
@@ -54,7 +54,7 @@ public static async Task<ApiError> Parse(HttpResponseMessage response)
5454
return Parse(content);
5555
}
5656

57-
internal static ApiError Parse(string content)
57+
internal static ApiError? Parse(string content)
5858
{
5959
try
6060
{

src/Auth0.Core/Exceptions/ApiException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected ApiException()
2323
/// Initializes a new instance of the <see cref="ApiException"/> class with a specified error message.
2424
/// </summary>
2525
/// <param name="message">The error message that explains the reason for the exception.</param>
26-
protected ApiException(string message)
26+
protected ApiException(string? message)
2727
: base(message)
2828
{
2929
}

src/Auth0.Core/Exceptions/ErrorApiException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ErrorApiException : ApiException
1515
/// <summary>
1616
/// Optional <see cref="Exceptions.ApiError"/> from the failing API call.
1717
/// </summary>
18-
public ApiError ApiError { get; }
18+
public ApiError? ApiError { get; }
1919

2020
/// <summary>
2121
/// <see cref="HttpStatusCode"/> code from the failing API call.
@@ -33,7 +33,7 @@ public ErrorApiException()
3333
/// Initializes a new instance of the <see cref="ErrorApiException"/> class with a specified error message.
3434
/// </summary>
3535
/// <param name="message">The error message that explains the reason for the exception.</param>
36-
public ErrorApiException(string message)
36+
public ErrorApiException(string? message)
3737
: base(message)
3838
{
3939
}
@@ -56,7 +56,7 @@ public ErrorApiException(string message, Exception innerException)
5656
/// </summary>
5757
/// <param name="statusCode"><see cref="HttpStatusCode"/>code of the failing API call.</param>
5858
/// <param name="apiError">Optional <see cref="ApiError"/> of the failing API call.</param>
59-
public ErrorApiException(HttpStatusCode statusCode, ApiError apiError = null)
59+
public ErrorApiException(HttpStatusCode statusCode, ApiError? apiError = null)
6060
: this(apiError == null ? statusCode.ToString() : apiError.Message)
6161
{
6262
StatusCode = statusCode;

src/Auth0.Core/Exceptions/QuotaLimit.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ namespace Auth0.Core.Exceptions
55
/// </summary>
66
public class ClientQuotaLimit
77
{
8-
public QuotaLimit PerHour { get; set; }
9-
public QuotaLimit PerDay { get; set; }
8+
public QuotaLimit? PerHour { get; set; }
9+
public QuotaLimit? PerDay { get; set; }
1010
}
1111

1212
/// <summary>
1313
/// Represents the Organization Quota Headers returned as part of the response.
1414
/// </summary>
1515
public class OrganizationQuotaLimit
1616
{
17-
public QuotaLimit PerHour { get; set; }
18-
public QuotaLimit PerDay { get; set; }
17+
public QuotaLimit? PerHour { get; set; }
18+
public QuotaLimit? PerDay { get; set; }
1919
}
2020

2121
/// <summary>

src/Auth0.Core/Exceptions/RateLimit.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ public class RateLimit
3535
/// <summary>
3636
/// Represents Client Quota Headers returned.
3737
/// </summary>
38-
public ClientQuotaLimit ClientQuotaLimit { get; internal set; }
38+
public ClientQuotaLimit? ClientQuotaLimit { get; internal set; }
3939

4040
/// <summary>
4141
/// Represents Client Quota Headers returned.
4242
/// </summary>
43-
public OrganizationQuotaLimit OrganizationQuotaLimit { get; internal set; }
43+
public OrganizationQuotaLimit? OrganizationQuotaLimit { get; internal set; }
4444

4545
/// <summary>
4646
/// Parse the rate limit headers into a <see cref="RateLimit"/> object.
4747
/// </summary>
4848
/// <param name="headers"><see cref="HttpHeaders"/> to parse.</param>
4949
/// <returns>Instance of <see cref="RateLimit"/> containing parsed rate limit headers.</returns>
50-
public static RateLimit Parse(HttpHeaders headers)
50+
public static RateLimit? Parse(HttpHeaders headers)
5151
{
5252
var headersKvp =
5353
headers?.ToDictionary(h => h.Key, h => h.Value);
@@ -58,14 +58,14 @@ public static RateLimit Parse(HttpHeaders headers)
5858
Remaining = GetHeaderValue(headersKvp, "x-ratelimit-remaining"),
5959
Reset = reset == 0 ? null : (DateTimeOffset?)epoch.AddSeconds(reset),
6060
RetryAfter = GetHeaderValue(headersKvp, "Retry-After"),
61-
ClientQuotaLimit = headersKvp.GetClientQuotaLimit(),
62-
OrganizationQuotaLimit = headersKvp.GetOrganizationQuotaLimit()
61+
ClientQuotaLimit = headersKvp?.GetClientQuotaLimit(),
62+
OrganizationQuotaLimit = headersKvp?.GetOrganizationQuotaLimit()
6363
};
6464
}
6565

66-
private static long GetHeaderValue(IDictionary<string, IEnumerable<string>> headers, string name)
66+
private static long GetHeaderValue(IDictionary<string, IEnumerable<string>>? headers, string name)
6767
{
68-
if (headers.TryGetValue(name, out var v) && long.TryParse(v?.FirstOrDefault(), out var value))
68+
if (headers != null && headers.TryGetValue(name, out var v) && long.TryParse(v?.FirstOrDefault(), out var value))
6969
return value;
7070

7171
return 0;

src/Auth0.Core/Exceptions/RateLimitApiException.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class RateLimitApiException : ApiException
1414
/// <summary>
1515
/// <see cref="RateLimit"/> as determined by the server.
1616
/// </summary>
17-
public RateLimit RateLimit { get; }
17+
public RateLimit? RateLimit { get; }
1818

1919
/// <summary>
2020
/// Optional <see cref="Exceptions.ApiError"/> from the failing API call.
2121
/// </summary>
22-
public ApiError ApiError { get; }
22+
public ApiError? ApiError { get; }
2323

2424
/// <summary>
2525
/// Initializes a new instance of the <see cref="RateLimitApiException"/> class.
@@ -31,7 +31,7 @@ public RateLimitApiException() {
3131
/// Initializes a new instance of the <see cref="RateLimitApiException"/> class with a specified error message.
3232
/// </summary>
3333
/// <param name="message">The error message that explains the reason for the exception.</param>
34-
public RateLimitApiException(string message) : base(message)
34+
public RateLimitApiException(string? message) : base(message)
3535
{
3636
}
3737

@@ -53,7 +53,7 @@ public RateLimitApiException(string message, Exception innerException)
5353
/// </summary>
5454
/// <param name="rateLimit"><see cref="Exceptions.RateLimit"/> received on the API call that failed.</param>
5555
/// <param name="apiError"><see cref="Exceptions.ApiError"/> received on the API call that failed.</param>
56-
public RateLimitApiException(RateLimit rateLimit, ApiError apiError = null)
56+
public RateLimitApiException(RateLimit? rateLimit, ApiError? apiError = null)
5757
: this("Rate limits exceeded")
5858
{
5959
RateLimit = rateLimit;

src/Auth0.Core/Extensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class Extensions
1212
/// </summary>
1313
/// <param name="headers">The source response headers</param>
1414
/// <returns><see cref="ClientQuotaLimit"/></returns>
15-
public static ClientQuotaLimit GetClientQuotaLimit(this IDictionary<string, IEnumerable<string>> headers)
15+
public static ClientQuotaLimit? GetClientQuotaLimit(this IDictionary<string, IEnumerable<string>> headers)
1616
{
1717
return ParseClientLimit(GetRawHeaders(headers, "Auth0-Client-Quota-Limit"));
1818
}
@@ -22,13 +22,13 @@ public static ClientQuotaLimit GetClientQuotaLimit(this IDictionary<string, IEnu
2222
/// </summary>
2323
/// <param name="headers">The source response headers</param>
2424
/// <returns><see cref="OrganizationQuotaLimit"/></returns>
25-
public static OrganizationQuotaLimit GetOrganizationQuotaLimit(
25+
public static OrganizationQuotaLimit? GetOrganizationQuotaLimit(
2626
this IDictionary<string, IEnumerable<string>> headers)
2727
{
2828
return ParseOrganizationLimit(GetRawHeaders(headers, "Auth0-Organization-Quota-Limit"));
2929
}
3030

31-
internal static string GetRawHeaders(IDictionary<string, IEnumerable<string>> headers, string headerName)
31+
internal static string? GetRawHeaders(IDictionary<string, IEnumerable<string>> headers, string headerName)
3232
{
3333
if (headers == null)
3434
{
@@ -37,13 +37,13 @@ internal static string GetRawHeaders(IDictionary<string, IEnumerable<string>> he
3737
return !headers.TryGetValue(headerName, out var values) ? null : values.FirstOrDefault();
3838
}
3939

40-
internal static ClientQuotaLimit ParseClientLimit(string headerValue)
40+
internal static ClientQuotaLimit? ParseClientLimit(string? headerValue)
4141
{
4242
if (string.IsNullOrEmpty(headerValue))
4343
{
4444
return null;
4545
}
46-
var buckets = headerValue.Split(',');
46+
var buckets = headerValue!.Split(',');
4747
var quotaClientLimit = new ClientQuotaLimit();
4848
foreach (var eachBucket in buckets)
4949
{
@@ -61,14 +61,14 @@ internal static ClientQuotaLimit ParseClientLimit(string headerValue)
6161
return quotaClientLimit;
6262
}
6363

64-
internal static OrganizationQuotaLimit ParseOrganizationLimit(string headerValue)
64+
internal static OrganizationQuotaLimit? ParseOrganizationLimit(string? headerValue)
6565
{
6666
if (string.IsNullOrEmpty(headerValue))
6767
{
6868
return null;
6969
}
7070

71-
var buckets = headerValue.Split(',');
71+
var buckets = headerValue!.Split(',');
7272
var quotaOrganizationLimit = new OrganizationQuotaLimit();
7373
foreach (var eachBucket in buckets)
7474
{
@@ -85,7 +85,7 @@ internal static OrganizationQuotaLimit ParseOrganizationLimit(string headerValue
8585
return quotaOrganizationLimit;
8686
}
8787

88-
internal static QuotaLimit ParseQuotaLimit(string headerValue, out string bucket)
88+
internal static QuotaLimit? ParseQuotaLimit(string headerValue, out string? bucket)
8989
{
9090
bucket = null;
9191

src/Auth0.Core/Serialization/ApiErrorConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class ApiErrorConverter : JsonConverter
1919

2020
public override bool CanWrite => false;
2121

22-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
22+
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
2323
{
2424
throw new NotImplementedException();
2525
}
@@ -29,7 +29,7 @@ public override bool CanConvert(Type objectType)
2929
return objectType.GetTypeInfo().IsClass;
3030
}
3131

32-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
32+
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
3333
{
3434
var instance = Activator.CreateInstance(objectType);
3535
var props = objectType.GetTypeInfo().DeclaredProperties.Where(p => p.CanWrite).ToList();
@@ -48,7 +48,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4848
}
4949
else if (extraDataProp != null)
5050
{
51-
((IDictionary<string, string>)extraDataProp.GetValue(instance))[name] = jp.Value.ToObject<string>(serializer);
51+
((IDictionary<string, string?>)extraDataProp.GetValue(instance))[name] = jp.Value.ToObject<string>(serializer);
5252
}
5353
}
5454

src/Auth0.Core/Serialization/StringOrObjectAsStringConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class StringOrObjectAsStringConverter : JsonConverter
88
{
99
public override bool CanWrite => false;
1010

11-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
11+
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
1212
{
1313
throw new NotImplementedException();
1414
}
@@ -18,7 +18,7 @@ public override bool CanConvert(Type objectType)
1818
return true;
1919
}
2020

21-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
21+
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
2222
{
2323
var instance = "";
2424

src/Auth0.Core/Serialization/StringOrStringArrayJsonConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public override bool CanConvert(Type objectType)
1313
return true;
1414
}
1515

16-
public override object ReadJson(
17-
JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
16+
public override object? ReadJson(
17+
JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
1818
{
1919
if (reader.TokenType == JsonToken.StartArray)
2020
{
@@ -32,7 +32,7 @@ public override object ReadJson(
3232
return null;
3333
}
3434

35-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
35+
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
3636
{
3737
throw new NotImplementedException();
3838
}

src/Auth0.Core/Utils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal static string Base64UrlEncode(byte[] input)
3434
return output;
3535
}
3636

37-
internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string, string> urlSegments, IDictionary<string, string> queryStrings, bool includeEmptyParameters = false)
37+
internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string, string>? urlSegments, IDictionary<string, string> queryStrings, bool includeEmptyParameters = false)
3838
{
3939
resource = ReplaceUrlSegments(resource, urlSegments);
4040

@@ -50,7 +50,7 @@ internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string
5050

5151
return new Uri(resource, UriKind.RelativeOrAbsolute);
5252
}
53-
internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string, string> urlSegments, IList<Tuple<string, string>> queryStringsTuple, bool includeEmptyParameters = false)
53+
internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string, string>? urlSegments, IList<Tuple<string, string>> queryStringsTuple, bool includeEmptyParameters = false)
5454
{
5555
resource = ReplaceUrlSegments(resource, urlSegments);
5656

@@ -72,7 +72,7 @@ internal static Uri BuildUri(string baseUrl, string resource, IDictionary<string
7272
/// See http://stackoverflow.com/a/6704287
7373
/// </summary>
7474
/// <param name="uriParts">The URI parts to combine.</param>
75-
internal static string CombineUriParts(params string[] uriParts)
75+
internal static string CombineUriParts(params string[]? uriParts)
7676
{
7777
var uri = string.Empty;
7878
if (uriParts != null && uriParts.Any())
@@ -110,7 +110,7 @@ private static string AddQueryString(IList<Tuple<string, string>> queryStrings,
110110
}
111111
return sb.ToString();
112112
}
113-
private static string AddQueryString(IDictionary<string, string> queryStrings, bool includeEmptyParameters)
113+
private static string? AddQueryString(IDictionary<string, string> queryStrings, bool includeEmptyParameters)
114114
{
115115
// Add the query strings
116116
var queryString = queryStrings?.Aggregate(new StringBuilder(), (sb, kvp) =>
@@ -135,7 +135,7 @@ private static string AddQueryString(IDictionary<string, string> queryStrings, b
135135
.ToString();
136136
return queryString;
137137
}
138-
private static string ReplaceUrlSegments(string resource, IDictionary<string, string> urlSegments)
138+
private static string ReplaceUrlSegments(string resource, IDictionary<string, string>? urlSegments)
139139
{
140140
// Replace the URL Segments
141141
if (urlSegments == null) return resource;

0 commit comments

Comments
 (0)