Skip to content

Commit e8c7f5a

Browse files
committed
Use the polyfilled generic Enum.IsDefined() on .NET Framework and manually replace missed ArgumentNullException.ThrowIfNull() guards
1 parent 9797f86 commit e8c7f5a

31 files changed

+137
-526
lines changed

gen/OpenIddict.Client.WebIntegration.Generators/OpenIddictClientWebIntegrationGenerator.cs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public sealed partial class OpenIddictClientWebIntegrationBuilder
7979
{{~ end ~}}
8080
public OpenIddictClientWebIntegrationBuilder Add{{ provider.name }}(Action<OpenIddictClientWebIntegrationBuilder.{{ provider.name }}> configuration)
8181
{
82-
if (configuration is null)
83-
{
84-
throw new ArgumentNullException(nameof(configuration));
85-
}
82+
ArgumentNullException.ThrowIfNull(configuration);
8683
8784
Services.Configure<OpenIddictClientOptions>(options =>
8885
{
@@ -132,10 +129,7 @@ public sealed partial class {{ provider.name }}
132129
[EditorBrowsable(EditorBrowsableState.Advanced)]
133130
public {{ provider.name }} AddClientAuthenticationMethods(params string[] methods)
134131
{
135-
if (methods is null)
136-
{
137-
throw new ArgumentNullException(nameof(methods));
138-
}
132+
ArgumentNullException.ThrowIfNull(methods);
139133
140134
return Set(registration => registration.ClientAuthenticationMethods.UnionWith(methods));
141135
}
@@ -149,10 +143,7 @@ public sealed partial class {{ provider.name }}
149143
[EditorBrowsable(EditorBrowsableState.Advanced)]
150144
public {{ provider.name }} AddCodeChallengeMethods(params string[] methods)
151145
{
152-
if (methods is null)
153-
{
154-
throw new ArgumentNullException(nameof(methods));
155-
}
146+
ArgumentNullException.ThrowIfNull(methods);
156147
157148
return Set(registration => registration.CodeChallengeMethods.UnionWith(methods));
158149
}
@@ -166,10 +157,7 @@ public sealed partial class {{ provider.name }}
166157
[EditorBrowsable(EditorBrowsableState.Advanced)]
167158
public {{ provider.name }} AddGrantTypes(params string[] types)
168159
{
169-
if (types is null)
170-
{
171-
throw new ArgumentNullException(nameof(types));
172-
}
160+
ArgumentNullException.ThrowIfNull(types);
173161
174162
return Set(registration => registration.GrantTypes.UnionWith(types));
175163
}
@@ -183,10 +171,7 @@ public sealed partial class {{ provider.name }}
183171
[EditorBrowsable(EditorBrowsableState.Advanced)]
184172
public {{ provider.name }} AddResponseModes(params string[] modes)
185173
{
186-
if (modes is null)
187-
{
188-
throw new ArgumentNullException(nameof(modes));
189-
}
174+
ArgumentNullException.ThrowIfNull(modes);
190175
191176
return Set(registration => registration.ResponseModes.UnionWith(modes));
192177
}
@@ -200,10 +185,7 @@ public sealed partial class {{ provider.name }}
200185
[EditorBrowsable(EditorBrowsableState.Advanced)]
201186
public {{ provider.name }} AddResponseTypes(params string[] types)
202187
{
203-
if (types is null)
204-
{
205-
throw new ArgumentNullException(nameof(types));
206-
}
188+
ArgumentNullException.ThrowIfNull(types);
207189
208190
return Set(registration => registration.ResponseTypes.UnionWith(types));
209191
}
@@ -215,10 +197,7 @@ public sealed partial class {{ provider.name }}
215197
/// <returns>The <see cref=""OpenIddictClientWebIntegrationBuilder.{{ provider.name }}""/> instance.</returns>
216198
public {{ provider.name }} AddScopes(params string[] scopes)
217199
{
218-
if (scopes is null)
219-
{
220-
throw new ArgumentNullException(nameof(scopes));
221-
}
200+
ArgumentNullException.ThrowIfNull(scopes);
222201
223202
return Set(registration => registration.Scopes.UnionWith(scopes));
224203
}

src/OpenIddict.Client.Owin/OpenIddictClientOwinBuilder.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public OpenIddictClientOwinBuilder(IServiceCollection services)
3838
/// <returns>The <see cref="OpenIddictClientOwinBuilder"/> instance.</returns>
3939
public OpenIddictClientOwinBuilder Configure(Action<OpenIddictClientOwinOptions> configuration)
4040
{
41-
if (configuration is null)
42-
{
43-
throw new ArgumentNullException(nameof(configuration));
44-
}
41+
ArgumentNullException.ThrowIfNull(configuration);
4542

4643
Services.Configure(configuration);
4744

@@ -137,10 +134,7 @@ public OpenIddictClientOwinBuilder EnableErrorPassthrough()
137134
/// <returns>The <see cref="OpenIddictClientOwinBuilder"/> instance.</returns>
138135
public OpenIddictClientOwinBuilder SetCookieManager(ICookieManager manager)
139136
{
140-
if (manager is null)
141-
{
142-
throw new ArgumentNullException(nameof(manager));
143-
}
137+
ArgumentNullException.ThrowIfNull(manager);
144138

145139
return Configure(options => options.CookieManager = manager);
146140
}

src/OpenIddict.Client.Owin/OpenIddictClientOwinConfiguration.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public OpenIddictClientOwinConfiguration(IServiceProvider provider)
3030
/// <inheritdoc/>
3131
public void Configure(OpenIddictClientOptions options)
3232
{
33-
if (options is null)
34-
{
35-
throw new ArgumentNullException(nameof(options));
36-
}
33+
ArgumentNullException.ThrowIfNull(options);
3734

3835
// Register the built-in event handlers used by the OpenIddict OWIN Client components.
3936
options.Handlers.AddRange(OpenIddictClientOwinHandlers.DefaultHandlers);
@@ -42,10 +39,7 @@ public void Configure(OpenIddictClientOptions options)
4239
/// <inheritdoc/>
4340
public void PostConfigure(string? name, OpenIddictClientOwinOptions options)
4441
{
45-
if (options is null)
46-
{
47-
throw new ArgumentNullException(nameof(options));
48-
}
42+
ArgumentNullException.ThrowIfNull(options);
4943

5044
// If no cookie manager was explicitly configured but the OWIN application builder was registered as a service
5145
// (which is required when using Autofac with the built-in Katana authentication middleware, as they require

src/OpenIddict.Client.Owin/OpenIddictClientOwinExtensions.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public static class OpenIddictClientOwinExtensions
2424
/// <returns>The <see cref="OpenIddictClientOwinBuilder"/> instance.</returns>
2525
public static OpenIddictClientOwinBuilder UseOwin(this OpenIddictClientBuilder builder)
2626
{
27-
if (builder is null)
28-
{
29-
throw new ArgumentNullException(nameof(builder));
30-
}
27+
ArgumentNullException.ThrowIfNull(builder);
3128

3229
builder.Services.AddWebEncoders();
3330

@@ -68,15 +65,8 @@ public static OpenIddictClientOwinBuilder UseOwin(this OpenIddictClientBuilder b
6865
public static OpenIddictClientBuilder UseOwin(
6966
this OpenIddictClientBuilder builder, Action<OpenIddictClientOwinBuilder> configuration)
7067
{
71-
if (builder is null)
72-
{
73-
throw new ArgumentNullException(nameof(builder));
74-
}
75-
76-
if (configuration is null)
77-
{
78-
throw new ArgumentNullException(nameof(configuration));
79-
}
68+
ArgumentNullException.ThrowIfNull(builder);
69+
ArgumentNullException.ThrowIfNull(configuration);
8070

8171
configuration(builder.UseOwin());
8272

src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlerFilters.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public RequirePostLogoutRedirectionEndpointPassthroughEnabled(IOptionsMonitor<Op
3030
/// <inheritdoc/>
3131
public ValueTask<bool> IsActiveAsync(BaseContext context)
3232
{
33-
if (context is null)
34-
{
35-
throw new ArgumentNullException(nameof(context));
36-
}
33+
ArgumentNullException.ThrowIfNull(context);
3734

3835
return new(_options.CurrentValue.EnablePostLogoutRedirectionEndpointPassthrough);
3936
}
@@ -53,10 +50,7 @@ public RequireRedirectionEndpointPassthroughEnabled(IOptionsMonitor<OpenIddictCl
5350
/// <inheritdoc/>
5451
public ValueTask<bool> IsActiveAsync(BaseContext context)
5552
{
56-
if (context is null)
57-
{
58-
throw new ArgumentNullException(nameof(context));
59-
}
53+
ArgumentNullException.ThrowIfNull(context);
6054

6155
return new(_options.CurrentValue.EnableRedirectionEndpointPassthrough);
6256
}
@@ -75,10 +69,7 @@ public RequireErrorPassthroughEnabled(IOptionsMonitor<OpenIddictClientOwinOption
7569
/// <inheritdoc/>
7670
public ValueTask<bool> IsActiveAsync(BaseContext context)
7771
{
78-
if (context is null)
79-
{
80-
throw new ArgumentNullException(nameof(context));
81-
}
72+
ArgumentNullException.ThrowIfNull(context);
8273

8374
return new(_options.CurrentValue.EnableErrorPassthrough);
8475
}
@@ -92,10 +83,7 @@ public sealed class RequireOwinRequest : IOpenIddictClientHandlerFilter<BaseCont
9283
/// <inheritdoc/>
9384
public ValueTask<bool> IsActiveAsync(BaseContext context)
9485
{
95-
if (context is null)
96-
{
97-
throw new ArgumentNullException(nameof(context));
98-
}
86+
ArgumentNullException.ThrowIfNull(context);
9987

10088
return new(context.Transaction.GetOwinRequest() is not null);
10189
}
@@ -114,10 +102,7 @@ public RequireTransportSecurityRequirementEnabled(IOptionsMonitor<OpenIddictClie
114102
/// <inheritdoc/>
115103
public ValueTask<bool> IsActiveAsync(BaseContext context)
116104
{
117-
if (context is null)
118-
{
119-
throw new ArgumentNullException(nameof(context));
120-
}
105+
ArgumentNullException.ThrowIfNull(context);
121106

122107
return new(!_options.CurrentValue.DisableTransportSecurityRequirement);
123108
}

src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.Authentication.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
using System.Collections.Immutable;
8+
using Microsoft.Extensions.Options;
89
using Owin;
910

1011
namespace OpenIddict.Client.Owin;
@@ -61,10 +62,7 @@ public sealed class ProcessQueryRequest : IOpenIddictClientHandler<ApplyAuthoriz
6162
/// <inheritdoc/>
6263
public ValueTask HandleAsync(ApplyAuthorizationRequestContext context)
6364
{
64-
if (context is null)
65-
{
66-
throw new ArgumentNullException(nameof(context));
67-
}
65+
ArgumentNullException.ThrowIfNull(context);
6866

6967
// This handler only applies to OWIN requests. If the HTTP context cannot be resolved,
7068
// this may indicate that the request was incorrectly processed by another server stack.

src/OpenIddict.Client.Owin/OpenIddictClientOwinHandlers.Session.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public sealed class ProcessQueryRequest : IOpenIddictClientHandler<ApplyEndSessi
5959
/// <inheritdoc/>
6060
public ValueTask HandleAsync(ApplyEndSessionRequestContext context)
6161
{
62-
if (context is null)
63-
{
64-
throw new ArgumentNullException(nameof(context));
65-
}
62+
ArgumentNullException.ThrowIfNull(context);
6663

6764
// This handler only applies to OWIN requests. If the HTTP context cannot be resolved,
6865
// this may indicate that the request was incorrectly processed by another server stack.

0 commit comments

Comments
 (0)