Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.

Commit bd78523

Browse files
committed
Replace NotNullAttribute with thrown exceptions
1 parent 24bc91b commit bd78523

11 files changed

+184
-31
lines changed

src/Microsoft.AspNet.StaticFiles/DefaultFilesExtensions.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using Microsoft.AspNet.Http;
56
using Microsoft.AspNet.StaticFiles;
6-
using Microsoft.Extensions.Internal;
77

88
namespace Microsoft.AspNet.Builder
99
{
@@ -17,8 +17,13 @@ public static class DefaultFilesExtensions
1717
/// </summary>
1818
/// <param name="builder"></param>
1919
/// <returns></returns>
20-
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder)
20+
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder)
2121
{
22+
if (builder == null)
23+
{
24+
throw new ArgumentNullException(nameof(builder));
25+
}
26+
2227
return builder.UseDefaultFiles(new DefaultFilesOptions());
2328
}
2429

@@ -28,8 +33,13 @@ public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBui
2833
/// <param name="builder"></param>
2934
/// <param name="requestPath">The relative request path.</param>
3035
/// <returns></returns>
31-
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath)
36+
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, string requestPath)
3237
{
38+
if (builder == null)
39+
{
40+
throw new ArgumentNullException(nameof(builder));
41+
}
42+
3343
return builder.UseDefaultFiles(new DefaultFilesOptions() { RequestPath = new PathString(requestPath) });
3444
}
3545

@@ -39,8 +49,18 @@ public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBui
3949
/// <param name="builder"></param>
4050
/// <param name="options"></param>
4151
/// <returns></returns>
42-
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] DefaultFilesOptions options)
52+
public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, DefaultFilesOptions options)
4353
{
54+
if (builder == null)
55+
{
56+
throw new ArgumentNullException(nameof(builder));
57+
}
58+
59+
if (options == null)
60+
{
61+
throw new ArgumentNullException(nameof(options));
62+
}
63+
4464
return builder.UseMiddleware<DefaultFilesMiddleware>(options);
4565
}
4666
}

src/Microsoft.AspNet.StaticFiles/DefaultFilesMiddleware.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Threading.Tasks;
56
using Microsoft.AspNet.Builder;
67
using Microsoft.AspNet.Hosting;
78
using Microsoft.AspNet.Http;
8-
using Microsoft.Extensions.Internal;
99
using Microsoft.Net.Http.Headers;
1010

1111
namespace Microsoft.AspNet.StaticFiles
@@ -26,8 +26,23 @@ public class DefaultFilesMiddleware
2626
/// </summary>
2727
/// <param name="next">The next middleware in the pipeline.</param>
2828
/// <param name="options">The configuration options for this middleware.</param>
29-
public DefaultFilesMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DefaultFilesOptions options)
29+
public DefaultFilesMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DefaultFilesOptions options)
3030
{
31+
if (next == null)
32+
{
33+
throw new ArgumentNullException(nameof(next));
34+
}
35+
36+
if (hostingEnv == null)
37+
{
38+
throw new ArgumentNullException(nameof(hostingEnv));
39+
}
40+
41+
if (options == null)
42+
{
43+
throw new ArgumentNullException(nameof(options));
44+
}
45+
3146
options.ResolveFileProvider(hostingEnv);
3247

3348
_next = next;

src/Microsoft.AspNet.StaticFiles/DirectoryBrowserExtensions.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using Microsoft.AspNet.Http;
56
using Microsoft.AspNet.StaticFiles;
6-
using Microsoft.Extensions.Internal;
77

88
namespace Microsoft.AspNet.Builder
99
{
@@ -17,8 +17,13 @@ public static class DirectoryBrowserExtensions
1717
/// </summary>
1818
/// <param name="builder"></param>
1919
/// <returns></returns>
20-
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder)
20+
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder)
2121
{
22+
if (builder == null)
23+
{
24+
throw new ArgumentNullException(nameof(builder));
25+
}
26+
2227
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions());
2328
}
2429

@@ -28,8 +33,13 @@ public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicatio
2833
/// <param name="builder"></param>
2934
/// <param name="requestPath">The relative request path.</param>
3035
/// <returns></returns>
31-
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath)
36+
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, string requestPath)
3237
{
38+
if (builder == null)
39+
{
40+
throw new ArgumentNullException(nameof(builder));
41+
}
42+
3343
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString(requestPath) });
3444
}
3545

@@ -39,8 +49,18 @@ public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicatio
3949
/// <param name="builder"></param>
4050
/// <param name="options"></param>
4151
/// <returns></returns>
42-
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] DirectoryBrowserOptions options)
52+
public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, DirectoryBrowserOptions options)
4353
{
54+
if (builder == null)
55+
{
56+
throw new ArgumentNullException(nameof(builder));
57+
}
58+
59+
if (options == null)
60+
{
61+
throw new ArgumentNullException(nameof(options));
62+
}
63+
4464
return builder.UseMiddleware<DirectoryBrowserMiddleware>(options);
4565
}
4666
}

src/Microsoft.AspNet.StaticFiles/DirectoryBrowserMiddleware.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.AspNet.FileProviders;
88
using Microsoft.AspNet.Hosting;
99
using Microsoft.AspNet.Http;
10-
using Microsoft.Extensions.Internal;
1110
using Microsoft.Net.Http.Headers;
1211

1312
namespace Microsoft.AspNet.StaticFiles
@@ -26,8 +25,23 @@ public class DirectoryBrowserMiddleware
2625
/// </summary>
2726
/// <param name="next">The next middleware in the pipeline.</param>
2827
/// <param name="options">The configuration for this middleware.</param>
29-
public DirectoryBrowserMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DirectoryBrowserOptions options)
28+
public DirectoryBrowserMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DirectoryBrowserOptions options)
3029
{
30+
if (next == null)
31+
{
32+
throw new ArgumentNullException(nameof(next));
33+
}
34+
35+
if (hostingEnv == null)
36+
{
37+
throw new ArgumentNullException(nameof(hostingEnv));
38+
}
39+
40+
if (options == null)
41+
{
42+
throw new ArgumentNullException(nameof(options));
43+
}
44+
3145
if (options.Formatter == null)
3246
{
3347
throw new ArgumentException(Resources.Args_NoFormatter);

src/Microsoft.AspNet.StaticFiles/DirectoryBrowserServiceExtensions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.Extensions.Internal;
5-
using Microsoft.AspNet.StaticFiles;
4+
using System;
65

76
namespace Microsoft.Extensions.DependencyInjection
87
{
@@ -16,8 +15,13 @@ public static class DirectoryBrowserServiceExtensions
1615
/// </summary>
1716
/// <param name="services"></param>
1817
/// <returns></returns>
19-
public static IServiceCollection AddDirectoryBrowser([NotNull] this IServiceCollection services)
18+
public static IServiceCollection AddDirectoryBrowser(this IServiceCollection services)
2019
{
20+
if (services == null)
21+
{
22+
throw new ArgumentNullException(nameof(services));
23+
}
24+
2125
return services.AddWebEncoders();
2226
}
2327
}

src/Microsoft.AspNet.StaticFiles/FileServerExtensions.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using Microsoft.AspNet.Http;
66
using Microsoft.AspNet.StaticFiles;
7-
using Microsoft.Extensions.Internal;
87

98
namespace Microsoft.AspNet.Builder
109
{
@@ -19,8 +18,13 @@ public static class FileServerExtensions
1918
/// </summary>
2019
/// <param name="builder"></param>
2120
/// <returns></returns>
22-
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder)
21+
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder)
2322
{
23+
if (builder == null)
24+
{
25+
throw new ArgumentNullException(nameof(builder));
26+
}
27+
2428
return builder.UseFileServer(new FileServerOptions());
2529
}
2630

@@ -30,8 +34,13 @@ public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuild
3034
/// <param name="builder"></param>
3135
/// <param name="enableDirectoryBrowsing">Should directory browsing be enabled?</param>
3236
/// <returns></returns>
33-
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, bool enableDirectoryBrowsing)
37+
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, bool enableDirectoryBrowsing)
3438
{
39+
if (builder == null)
40+
{
41+
throw new ArgumentNullException(nameof(builder));
42+
}
43+
3544
return builder.UseFileServer(new FileServerOptions() { EnableDirectoryBrowsing = enableDirectoryBrowsing });
3645
}
3746

@@ -41,8 +50,18 @@ public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuild
4150
/// <param name="builder"></param>
4251
/// <param name="requestPath">The relative request path.</param>
4352
/// <returns></returns>
44-
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath)
53+
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, string requestPath)
4554
{
55+
if (builder == null)
56+
{
57+
throw new ArgumentNullException(nameof(builder));
58+
}
59+
60+
if (requestPath == null)
61+
{
62+
throw new ArgumentNullException(nameof(requestPath));
63+
}
64+
4665
return builder.UseFileServer(new FileServerOptions() { RequestPath = new PathString(requestPath) });
4766
}
4867

@@ -52,8 +71,18 @@ public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuild
5271
/// <param name="builder"></param>
5372
/// <param name="options"></param>
5473
/// <returns></returns>
55-
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] FileServerOptions options)
74+
public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, FileServerOptions options)
5675
{
76+
if (builder == null)
77+
{
78+
throw new ArgumentNullException(nameof(builder));
79+
}
80+
81+
if (options == null)
82+
{
83+
throw new ArgumentNullException(nameof(options));
84+
}
85+
5786
if (options == null)
5887
{
5988
throw new ArgumentNullException(nameof(options));

src/Microsoft.AspNet.StaticFiles/SendFileExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.AspNet.Builder;
7-
using Microsoft.Extensions.Internal;
87

98
namespace Microsoft.AspNet.StaticFiles
109
{
@@ -18,8 +17,13 @@ public static class SendFileExtensions
1817
/// </summary>
1918
/// <param name="builder"></param>
2019
/// <returns></returns>
21-
public static IApplicationBuilder UseSendFileFallback([NotNull] this IApplicationBuilder builder)
20+
public static IApplicationBuilder UseSendFileFallback(this IApplicationBuilder builder)
2221
{
22+
if (builder == null)
23+
{
24+
throw new ArgumentNullException(nameof(builder));
25+
}
26+
2327
/* TODO builder.GetItem(typeof(ISendFile))
2428
2529
// Check for advertised support

src/Microsoft.AspNet.StaticFiles/SendFileMiddleware.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.AspNet.Builder;
99
using Microsoft.AspNet.Http;
1010
using Microsoft.AspNet.Http.Features;
11-
using Microsoft.Extensions.Internal;
1211
using Microsoft.Extensions.Logging;
1312

1413
namespace Microsoft.AspNet.StaticFiles
@@ -29,8 +28,18 @@ public class SendFileMiddleware
2928
/// </summary>
3029
/// <param name="next">The next middleware in the pipeline.</param>
3130
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
32-
public SendFileMiddleware([NotNull] RequestDelegate next, [NotNull] ILoggerFactory loggerFactory)
31+
public SendFileMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
3332
{
33+
if (next == null)
34+
{
35+
throw new ArgumentNullException(nameof(next));
36+
}
37+
38+
if (loggerFactory == null)
39+
{
40+
throw new ArgumentNullException(nameof(loggerFactory));
41+
}
42+
3443
_next = next;
3544
_logger = loggerFactory.CreateLogger<SendFileMiddleware>();
3645
}

0 commit comments

Comments
 (0)