Replace NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-10-06 17:02:59 -07:00
parent 24bc91b958
commit bd78523011
11 changed files with 184 additions and 31 deletions

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles; using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder) public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseDefaultFiles(new DefaultFilesOptions()); return builder.UseDefaultFiles(new DefaultFilesOptions());
} }
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="requestPath">The relative request path.</param> /// <param name="requestPath">The relative request path.</param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, string requestPath)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseDefaultFiles(new DefaultFilesOptions() { RequestPath = new PathString(requestPath) }); return builder.UseDefaultFiles(new DefaultFilesOptions() { RequestPath = new PathString(requestPath) });
} }
@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDefaultFiles([NotNull] this IApplicationBuilder builder, [NotNull] DefaultFilesOptions options) public static IApplicationBuilder UseDefaultFiles(this IApplicationBuilder builder, DefaultFilesOptions options)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return builder.UseMiddleware<DefaultFilesMiddleware>(options); return builder.UseMiddleware<DefaultFilesMiddleware>(options);
} }
} }

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Extensions.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.StaticFiles namespace Microsoft.AspNet.StaticFiles
@ -26,8 +26,23 @@ namespace Microsoft.AspNet.StaticFiles
/// </summary> /// </summary>
/// <param name="next">The next middleware in the pipeline.</param> /// <param name="next">The next middleware in the pipeline.</param>
/// <param name="options">The configuration options for this middleware.</param> /// <param name="options">The configuration options for this middleware.</param>
public DefaultFilesMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DefaultFilesOptions options) public DefaultFilesMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DefaultFilesOptions options)
{ {
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
if (hostingEnv == null)
{
throw new ArgumentNullException(nameof(hostingEnv));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
options.ResolveFileProvider(hostingEnv); options.ResolveFileProvider(hostingEnv);
_next = next; _next = next;

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles; using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder) public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions()); return builder.UseDirectoryBrowser(new DirectoryBrowserOptions());
} }
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="requestPath">The relative request path.</param> /// <param name="requestPath">The relative request path.</param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, string requestPath)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString(requestPath) }); return builder.UseDirectoryBrowser(new DirectoryBrowserOptions() { RequestPath = new PathString(requestPath) });
} }
@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseDirectoryBrowser([NotNull] this IApplicationBuilder builder, [NotNull] DirectoryBrowserOptions options) public static IApplicationBuilder UseDirectoryBrowser(this IApplicationBuilder builder, DirectoryBrowserOptions options)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return builder.UseMiddleware<DirectoryBrowserMiddleware>(options); return builder.UseMiddleware<DirectoryBrowserMiddleware>(options);
} }
} }

View File

@ -7,7 +7,6 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Extensions.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.StaticFiles namespace Microsoft.AspNet.StaticFiles
@ -26,8 +25,23 @@ namespace Microsoft.AspNet.StaticFiles
/// </summary> /// </summary>
/// <param name="next">The next middleware in the pipeline.</param> /// <param name="next">The next middleware in the pipeline.</param>
/// <param name="options">The configuration for this middleware.</param> /// <param name="options">The configuration for this middleware.</param>
public DirectoryBrowserMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DirectoryBrowserOptions options) public DirectoryBrowserMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, DirectoryBrowserOptions options)
{ {
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
if (hostingEnv == null)
{
throw new ArgumentNullException(nameof(hostingEnv));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (options.Formatter == null) if (options.Formatter == null)
{ {
throw new ArgumentException(Resources.Args_NoFormatter); throw new ArgumentException(Resources.Args_NoFormatter);

View File

@ -1,8 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.Internal; using System;
using Microsoft.AspNet.StaticFiles;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
@ -16,8 +15,13 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary> /// </summary>
/// <param name="services"></param> /// <param name="services"></param>
/// <returns></returns> /// <returns></returns>
public static IServiceCollection AddDirectoryBrowser([NotNull] this IServiceCollection services) public static IServiceCollection AddDirectoryBrowser(this IServiceCollection services)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
return services.AddWebEncoders(); return services.AddWebEncoders();
} }
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles; using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder) public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseFileServer(new FileServerOptions()); return builder.UseFileServer(new FileServerOptions());
} }
@ -30,8 +34,13 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="enableDirectoryBrowsing">Should directory browsing be enabled?</param> /// <param name="enableDirectoryBrowsing">Should directory browsing be enabled?</param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, bool enableDirectoryBrowsing) public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, bool enableDirectoryBrowsing)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseFileServer(new FileServerOptions() { EnableDirectoryBrowsing = enableDirectoryBrowsing }); return builder.UseFileServer(new FileServerOptions() { EnableDirectoryBrowsing = enableDirectoryBrowsing });
} }
@ -41,8 +50,18 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="requestPath">The relative request path.</param> /// <param name="requestPath">The relative request path.</param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, string requestPath)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (requestPath == null)
{
throw new ArgumentNullException(nameof(requestPath));
}
return builder.UseFileServer(new FileServerOptions() { RequestPath = new PathString(requestPath) }); return builder.UseFileServer(new FileServerOptions() { RequestPath = new PathString(requestPath) });
} }
@ -52,8 +71,18 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseFileServer([NotNull] this IApplicationBuilder builder, [NotNull] FileServerOptions options) public static IApplicationBuilder UseFileServer(this IApplicationBuilder builder, FileServerOptions options)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (options == null) if (options == null)
{ {
throw new ArgumentNullException(nameof(options)); throw new ArgumentNullException(nameof(options));

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.StaticFiles namespace Microsoft.AspNet.StaticFiles
{ {
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.StaticFiles
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseSendFileFallback([NotNull] this IApplicationBuilder builder) public static IApplicationBuilder UseSendFileFallback(this IApplicationBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
/* TODO builder.GetItem(typeof(ISendFile)) /* TODO builder.GetItem(typeof(ISendFile))
// Check for advertised support // Check for advertised support

View File

@ -8,7 +8,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.StaticFiles namespace Microsoft.AspNet.StaticFiles
@ -29,8 +28,18 @@ namespace Microsoft.AspNet.StaticFiles
/// </summary> /// </summary>
/// <param name="next">The next middleware in the pipeline.</param> /// <param name="next">The next middleware in the pipeline.</param>
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param> /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
public SendFileMiddleware([NotNull] RequestDelegate next, [NotNull] ILoggerFactory loggerFactory) public SendFileMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
{ {
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
_next = next; _next = next;
_logger = loggerFactory.CreateLogger<SendFileMiddleware>(); _logger = loggerFactory.CreateLogger<SendFileMiddleware>();
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles; using Microsoft.AspNet.StaticFiles;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder) public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseStaticFiles(new StaticFileOptions()); return builder.UseStaticFiles(new StaticFileOptions());
} }
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="requestPath">The relative request path.</param> /// <param name="requestPath">The relative request path.</param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder, [NotNull] string requestPath) public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, string requestPath)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString(requestPath) }); return builder.UseStaticFiles(new StaticFileOptions() { RequestPath = new PathString(requestPath) });
} }
@ -39,8 +49,18 @@ namespace Microsoft.AspNet.Builder
/// <param name="builder"></param> /// <param name="builder"></param>
/// <param name="options"></param> /// <param name="options"></param>
/// <returns></returns> /// <returns></returns>
public static IApplicationBuilder UseStaticFiles([NotNull] this IApplicationBuilder builder, [NotNull] StaticFileOptions options) public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder builder, StaticFileOptions options)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return builder.UseMiddleware<StaticFileMiddleware>(options); return builder.UseMiddleware<StaticFileMiddleware>(options);
} }
} }

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.StaticFiles namespace Microsoft.AspNet.StaticFiles
@ -27,8 +26,28 @@ namespace Microsoft.AspNet.StaticFiles
/// <param name="next">The next middleware in the pipeline.</param> /// <param name="next">The next middleware in the pipeline.</param>
/// <param name="options">The configuration options.</param> /// <param name="options">The configuration options.</param>
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param> /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
public StaticFileMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] StaticFileOptions options, [NotNull] ILoggerFactory loggerFactory) public StaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, StaticFileOptions options, ILoggerFactory loggerFactory)
{ {
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
if (hostingEnv == null)
{
throw new ArgumentNullException(nameof(hostingEnv));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
if (options.ContentTypeProvider == null) if (options.ContentTypeProvider == null)
{ {
throw new ArgumentException(Resources.Args_NoContentTypeProvider); throw new ArgumentException(Resources.Args_NoContentTypeProvider);

View File

@ -10,7 +10,6 @@
"Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*", "Microsoft.AspNet.FileProviders.Abstractions": "1.0.0-*",
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*", "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Extensions.WebEncoders": "1.0.0-*" "Microsoft.Extensions.WebEncoders": "1.0.0-*"
}, },
"frameworks": { "frameworks": {