From 3a876e387f1d7816264a0444c91efe41bde99eaa Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 30 Sep 2015 21:04:56 -0700 Subject: [PATCH] Replacing NotNullAttribute with thrown exceptions --- .../ApiDescriptionExtensions.cs | 21 +- .../ApiDescriptionGroupCollection.cs | 9 +- .../ApiDescriptionProviderContext.cs | 9 +- .../DefaultApiDescriptionProvider.cs | 9 +- .../MvcApiExplorerMvcCoreBuilderExtensions.cs | 11 +- .../IApiDescriptionProvider.cs | 6 +- .../project.json | 3 +- .../AcceptVerbsAttribute.cs | 7 +- .../DefaultActionConstraintProvider.cs | 10 +- .../ActionConstraints/HttpMethodConstraint.cs | 15 +- .../ApplicationModels/ActionModel.cs | 23 +- .../ApplicationModels/ApiExplorerModel.cs | 9 +- .../ApplicationModelConventions.cs | 16 +- .../ApplicationModelProviderContext.cs | 11 +- .../ApplicationModels/AttributeRouteModel.cs | 15 +- .../AuthorizationApplicationModelProvider.cs | 15 +- .../ApplicationModels/ControllerModel.cs | 23 +- .../DefaultApplicationModelProvider.cs | 81 +++- .../IActionModelConvention.cs | 4 +- .../IApplicationModelConvention.cs | 4 +- .../IApplicationModelProvider.cs | 8 +- .../IControllerModelConvention.cs | 4 +- .../IParameterModelConvention.cs | 4 +- .../ApplicationModels/ParameterModel.cs | 23 +- .../ApplicationModels/PropertyModel.cs | 23 +- .../BadRequestObjectResult.cs | 9 +- .../BindAttribute.cs | 8 +- .../MvcApplicationBuilderExtensions.cs | 29 +- .../ChallengeResult.cs | 9 +- .../ConsumesAttribute.cs | 21 +- .../ContentResult.cs | 9 +- .../ControllerActionDescriptorProvider.cs | 34 +- .../Controllers/ControllerActionInvoker.cs | 108 ++++- .../ControllerActionInvokerProvider.cs | 39 +- .../DefaultControllerActionArgumentBinder.cs | 36 +- .../Controllers/DefaultControllerActivator.cs | 14 +- .../Controllers/DefaultControllerFactory.cs | 8 +- .../DefaultControllerTypeProvider.cs | 15 +- .../Controllers/FilterActionInvoker.cs | 75 ++- .../IControllerActionArgumentBinder.cs | 7 +- .../ServiceBasedControllerActivator.cs | 13 +- .../StaticControllerTypeProvider.cs | 9 +- .../CreatedAtActionResult.cs | 16 +- .../CreatedAtRouteResult.cs | 8 +- .../CreatedResult.cs | 22 +- .../ApplicationModelConventionExtensions.cs | 44 +- .../MvcCoreMvcBuilderExtensions.cs | 59 ++- .../MvcCoreMvcCoreBuilderExtensions.cs | 45 +- .../MvcCoreServiceCollectionExtensions.cs | 17 +- src/Microsoft.AspNet.Mvc.Core/EmptyResult.cs | 11 +- .../FileContentResult.cs | 23 +- src/Microsoft.AspNet.Mvc.Core/FileResult.cs | 22 +- .../FileStreamResult.cs | 15 +- .../Filters/ActionFilterAttribute.cs | 37 +- .../Filters/AuthorizationFilterAttribute.cs | 24 +- .../Filters/AuthorizeFilter.cs | 15 +- .../Filters/ControllerActionFilter.cs | 15 +- .../Filters/ControllerResultFilter.cs | 15 +- .../Filters/DefaultFilterProvider.cs | 10 +- .../Filters/ExceptionFilterAttribute.cs | 10 +- .../Filters/FilterCollection.cs | 31 +- .../Filters/FilterDescriptorOrderComparer.cs | 14 +- .../Filters/FilterItemOrderComparer.cs | 14 +- .../Filters/ResponseCacheFilter.cs | 19 +- .../Filters/ResultFilterAttribute.cs | 19 +- .../FormatFilterAttribute.cs | 8 +- .../Formatters/FormatFilter.cs | 24 +- .../Formatters/FormatterMappings.cs | 27 +- .../Formatters/OutputFormatter.cs | 31 +- .../Formatters/StreamOutputFormatter.cs | 16 +- .../Formatters/StringOutputFormatter.cs | 11 + .../HttpDeleteAttribute.cs | 8 +- .../HttpGetAttribute.cs | 8 +- .../HttpHeadAttribute.cs | 10 +- .../HttpPatchAttribute.cs | 8 +- .../HttpPostAttribute.cs | 8 +- .../HttpPutAttribute.cs | 8 +- .../HttpResponseStreamWriter.cs | 15 +- .../HttpStatusCodeResult.cs | 9 +- src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs | 5 +- .../ActionDescriptorsCollection.cs | 9 +- .../Infrastructure/DefaultActionSelector.cs | 17 +- .../DefaultTypeActivatorCache.cs | 15 +- .../Infrastructure/MvcRouteHandler.cs | 19 +- .../RouteConstraintAttribute.cs | 22 +- .../Internal/MvcBuilder.cs | 9 +- .../Internal/MvcCoreBuilder.cs | 9 +- .../Internal/NonDisposableStream.cs | 10 +- .../ModelBinding/ArrayModelBinder.cs | 14 +- .../BindingSourceValueProvider.cs | 14 +- .../ModelBinding/BodyModelBinder.cs | 8 +- .../ModelBinding/ByteArrayModelBinder.cs | 8 +- .../ModelBinding/CollectionModelBinder.cs | 15 +- .../ModelBinding/CompositeModelBinder.cs | 16 +- .../ModelBinding/CompositeValueProvider.cs | 34 +- .../DictionaryBasedValueProvider.cs | 26 +- .../ModelBinding/DictionaryModelBinder.cs | 8 +- .../EmptyModelMetadataProvider.cs | 6 + .../ModelBinding/FormCollectionModelBinder.cs | 8 +- .../ModelBinding/FormFileModelBinder.cs | 14 +- .../ModelBinding/FormValueProviderFactory.cs | 9 +- .../IBindingSourceValueProvider.cs | 4 +- .../ModelBinding/JQueryFormValueProvider.cs | 18 +- .../JQueryFormValueProviderFactory.cs | 10 +- .../BindingMetadataProviderContext.cs | 11 +- .../DefaultBindingMetadataProvider.cs | 8 +- ...DefaultCompositeMetadataDetailsProvider.cs | 23 +- .../Metadata/DefaultMetadataDetails.cs | 8 +- .../Metadata/DefaultModelMetadata.cs | 21 +- .../Metadata/DefaultModelMetadataProvider.cs | 18 +- .../DefaultValidationMetadataProvider.cs | 9 +- .../DisplayMetadataProviderContext.cs | 11 +- .../Metadata/IBindingMetadataProvider.cs | 4 +- .../Metadata/IDisplayMetadataProvider.cs | 4 +- .../Metadata/IValidationMetadataProvider.cs | 4 +- .../ModelBinding/Metadata/ModelAttributes.cs | 39 +- .../ValidationMetadataProviderContext.cs | 11 +- .../ModelBinding/ModelBindingHelper.cs | 430 +++++++++++++++--- .../ModelBinding/MutableObjectModelBinder.cs | 59 ++- .../ModelBinding/PrefixContainer.cs | 15 +- .../QueryStringValueProviderFactory.cs | 9 +- .../ReadableStringCollectionValueProvider.cs | 30 +- .../RouteValueValueProviderFactory.cs | 9 +- .../CompositeClientModelValidatorProvider.cs | 14 +- .../CompositeModelValidatorProvider.cs | 9 +- .../DefaultTypeBasedExcludeFilter.cs | 15 +- .../DefaultTypeNameBasedExcludeFilter.cs | 15 +- .../ExcludeTypeValidationFilterCollection.cs | 17 +- .../IExcludeTypeValidationFilter.cs | 3 +- .../Validation/SimpleTypesExcludeFilter.cs | 5 + .../ValueProviderResultExtensions.cs | 10 +- .../ModelMetadataTypeAttribute.cs | 8 +- src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs | 17 +- .../PhysicalFileProviderResult.cs | 40 +- .../ProducesAttribute.cs | 22 +- .../RedirectResult.cs | 22 +- .../RedirectToActionResult.cs | 9 +- .../RedirectToRouteResult.cs | 8 +- .../RequireHttpsAttribute.cs | 8 +- .../ResponseCacheAttribute.cs | 10 +- .../RouteAttribute.cs | 8 +- .../Routing/AttributeRoute.cs | 29 +- .../Routing/AttributeRouting.cs | 13 +- .../Routing/HttpMethodAttribute.cs | 14 +- .../Routing/InnerAttributeRoute.cs | 52 ++- .../Routing/KnownRouteValueConstraint.cs | 30 +- .../Routing/UrlHelper.cs | 15 +- .../SerializableError.cs | 10 +- .../ServiceFilterAttribute.cs | 15 +- .../TypeFilterAttribute.cs | 15 +- .../UrlHelperExtensions.cs | 100 +++- .../VirtualFileProviderResult.cs | 37 +- src/Microsoft.AspNet.Mvc.Core/project.json | 4 - .../CorsApplicationModelProvider.cs | 39 +- .../CorsAuthorizationFilter.cs | 20 +- .../CorsAuthorizationFilterFactory.cs | 18 +- .../MvcCorsMvcCoreBuilderExtensions.cs | 38 +- .../DisableCorsAuthorizationFilter.cs | 20 +- src/Microsoft.AspNet.Mvc.Cors/project.json | 6 +- .../Controller.cs | 8 - .../SkipStatusCodePagesAttribute.cs | 4 - .../DefaultApplicationModelProviderTest.cs | 19 +- .../ConsumesAttributeTests.cs | 5 +- .../ControllerActionArgumentBinderTests.cs | 5 + ...ControllerActionDescriptorProviderTests.cs | 3 +- .../ControllerActionInvokerTest.cs | 27 +- ...pplicationModelConventionExtensionsTest.cs | 4 +- .../Filters/AuthorizeFilterTest.cs | 4 +- .../Formatters/OutputFormatterTests.cs | 3 +- .../DefaultActionSelectorTests.cs | 2 +- .../ModelBinding/ByteArrayModelBinderTests.cs | 5 +- .../ModelBinding/CollectionModelBinderTest.cs | 12 +- .../ModelBinding/CompositeModelBinderTest.cs | 8 + .../ModelBinding/DictionaryModelBinderTest.cs | 5 + .../KeyValuePairModelBinderTest.cs | 6 +- .../ModelBinding/ModelBindingContextTest.cs | 3 +- .../ModelBinding/ModelBindingHelperTest.cs | 85 ++-- .../ModelBinding/ModelBindingResultTest.cs | 1 - .../MutableObjectModelBinderTest.cs | 9 +- .../ModelBinding/SimpleValueProvider.cs | 1 - .../RequireHttpsAttributeTests.cs | 8 +- .../Routing/KnownRouteValueConstraintTests.cs | 35 +- .../DataAnnotationsModelValidatorTest.cs | 1 - .../JsonOutputFormatterTests.cs | 12 +- 184 files changed, 2739 insertions(+), 803 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionExtensions.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionExtensions.cs index 6bf8421a0e..4dda00d8c3 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionExtensions.cs @@ -1,7 +1,7 @@ // 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. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Mvc.ApiExplorer { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer /// The type of the property. /// The . /// The property or the default value of . - public static T GetProperty([NotNull] this ApiDescription apiDescription) + public static T GetProperty(this ApiDescription apiDescription) { + if (apiDescription == null) + { + throw new ArgumentNullException(nameof(apiDescription)); + } + object value; if (apiDescription.Properties.TryGetValue(typeof(T), out value)) { @@ -37,8 +42,18 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer /// The type of the property. /// The . /// The value of the property. - public static void SetProperty([NotNull] this ApiDescription apiDescription, [NotNull] T value) + public static void SetProperty(this ApiDescription apiDescription, T value) { + if (apiDescription == null) + { + throw new ArgumentNullException(nameof(apiDescription)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + apiDescription.Properties[typeof(T)] = value; } } diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs index 5b9c62f832..8d2339f8db 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApiExplorer { @@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer /// /// The list of . /// The unique version of discovered groups. - public ApiDescriptionGroupCollection([NotNull] IReadOnlyList items, int version) + public ApiDescriptionGroupCollection(IReadOnlyList items, int version) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + Items = items; Version = version; } diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionProviderContext.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionProviderContext.cs index 0fe65eab7d..3a6d1b26ef 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/ApiDescriptionProviderContext.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApiExplorer { @@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer /// Creates a new instance of . /// /// The list of actions. - public ApiDescriptionProviderContext([NotNull] IReadOnlyList actions) + public ApiDescriptionProviderContext(IReadOnlyList actions) { + if (actions == null) + { + throw new ArgumentNullException(nameof(actions)); + } + Actions = actions; Results = new List(); diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs index dcb03587bf..53fa22600c 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs @@ -53,8 +53,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer } /// - public void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context) + public void OnProvidersExecuting(ApiDescriptionProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var action in context.Actions.OfType()) { var extensionData = action.GetProperty(); @@ -69,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer } } - public void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context) + public void OnProvidersExecuted(ApiDescriptionProviderContext context) { } diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/DependencyInjection/MvcApiExplorerMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/DependencyInjection/MvcApiExplorerMvcCoreBuilderExtensions.cs index fc22f0cf1e..a561577208 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/DependencyInjection/MvcApiExplorerMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/DependencyInjection/MvcApiExplorerMvcCoreBuilderExtensions.cs @@ -1,16 +1,21 @@ -// 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. +using System; using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { public static class MvcApiExplorerMvcCoreBuilderExtensions { - public static IMvcCoreBuilder AddApiExplorer([NotNull] this IMvcCoreBuilder builder) + public static IMvcCoreBuilder AddApiExplorer(this IMvcCoreBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + AddApiExplorerServices(builder.Services); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/IApiDescriptionProvider.cs b/src/Microsoft.AspNet.Mvc.ApiExplorer/IApiDescriptionProvider.cs index 93a781a26b..ec0caa4493 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/IApiDescriptionProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/IApiDescriptionProvider.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApiExplorer { public interface IApiDescriptionProvider @@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer /// int Order { get; } - void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context); + void OnProvidersExecuting(ApiDescriptionProviderContext context); - void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context); + void OnProvidersExecuted(ApiDescriptionProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.ApiExplorer/project.json b/src/Microsoft.AspNet.Mvc.ApiExplorer/project.json index 37ce67022c..832c7a4d2c 100644 --- a/src/Microsoft.AspNet.Mvc.ApiExplorer/project.json +++ b/src/Microsoft.AspNet.Mvc.ApiExplorer/project.json @@ -11,8 +11,7 @@ "dependencies": { "Microsoft.AspNet.Mvc.Core": "6.0.0-*", "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }, - "Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" }, - "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" } + "Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" } }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.Mvc.Core/AcceptVerbsAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/AcceptVerbsAttribute.cs index 1c06a4d426..bf7aa1c96b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/AcceptVerbsAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/AcceptVerbsAttribute.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -22,9 +21,13 @@ namespace Microsoft.AspNet.Mvc /// Initializes a new instance of the class. /// /// The HTTP method the action supports. - public AcceptVerbsAttribute([NotNull] string method) + public AcceptVerbsAttribute(string method) : this(new string[] { method }) { + if (method == null) + { + throw new ArgumentNullException(nameof(method)); + } } /// diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs index f5e046bccc..1352424a5e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ActionConstraints { @@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints } /// - public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context) + public void OnProvidersExecuting(ActionConstraintProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var item in context.Results) { ProvideConstraint(item, context.HttpContext.RequestServices); @@ -32,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints } /// - public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context) + public void OnProvidersExecuted(ActionConstraintProviderContext context) { } diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/HttpMethodConstraint.cs b/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/HttpMethodConstraint.cs index d1d988ee8e..01138a71b5 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/HttpMethodConstraint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionConstraints/HttpMethodConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.ActionConstraints @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints private readonly string PreflightHttpMethod = "OPTIONS"; // Empty collection means any method will be accepted. - public HttpMethodConstraint([NotNull] IEnumerable httpMethods) + public HttpMethodConstraint(IEnumerable httpMethods) { + if (httpMethods == null) + { + throw new ArgumentNullException(nameof(httpMethods)); + } + var methods = new List(); foreach (var method in httpMethods) @@ -51,8 +55,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints get { return HttpMethodConstraintOrder; } } - public bool Accept([NotNull] ActionConstraintContext context) + public bool Accept(ActionConstraintContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (_methods.Count == 0) { return true; diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs index 477cb316ba..7e5c08fb7f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs @@ -1,6 +1,7 @@ // 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. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -8,7 +9,6 @@ using System.Reflection; using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public class ActionModel : ICommonModel, IFilterModel, IApiExplorerModel { public ActionModel( - [NotNull] MethodInfo actionMethod, - [NotNull] IReadOnlyList attributes) + MethodInfo actionMethod, + IReadOnlyList attributes) { + if (actionMethod == null) + { + throw new ArgumentNullException(nameof(actionMethod)); + } + + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + ActionMethod = actionMethod; ApiExplorer = new ApiExplorerModel(); @@ -32,8 +42,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels Properties = new Dictionary(); } - public ActionModel([NotNull] ActionModel other) + public ActionModel(ActionModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + ActionMethod = other.ActionMethod; ActionName = other.ActionName; diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApiExplorerModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApiExplorerModel.cs index 038a3020fd..eea574cb16 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApiExplorerModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApiExplorerModel.cs @@ -1,7 +1,7 @@ // 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. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Creates a new with properties copied from . /// /// The to copy. - public ApiExplorerModel([NotNull] ApiExplorerModel other) + public ApiExplorerModel(ApiExplorerModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + GroupName = other.GroupName; IsVisible = other.IsVisible; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs index 15392ba3ed..0a337067bf 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -18,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// The . /// The set of conventions. public static void ApplyConventions( - [NotNull] ApplicationModel applicationModel, - [NotNull] IEnumerable conventions) + ApplicationModel applicationModel, + IEnumerable conventions) { + if (applicationModel == null) + { + throw new ArgumentNullException(nameof(applicationModel)); + } + + if (conventions == null) + { + throw new ArgumentNullException(nameof(conventions)); + } + // Conventions are applied from the outside-in to allow for scenarios where an action overrides // a controller, etc. foreach (var convention in conventions) diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelProviderContext.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelProviderContext.cs index e6bb3fa760..a1636c3898 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModelProviderContext.cs @@ -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. +using System; using System.Collections.Generic; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -12,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// public class ApplicationModelProviderContext { - public ApplicationModelProviderContext([NotNull] IEnumerable controllerTypes) + public ApplicationModelProviderContext(IEnumerable controllerTypes) { + if (controllerTypes == null) + { + throw new ArgumentNullException(nameof(controllerTypes)); + } + ControllerTypes = controllerTypes; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AttributeRouteModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AttributeRouteModel.cs index 96fa3bdc11..6bcdcdcb8d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AttributeRouteModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AttributeRouteModel.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -19,16 +18,26 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels { } - public AttributeRouteModel([NotNull] IRouteTemplateProvider templateProvider) + public AttributeRouteModel(IRouteTemplateProvider templateProvider) { + if (templateProvider == null) + { + throw new ArgumentNullException(nameof(templateProvider)); + } + Attribute = templateProvider; Template = templateProvider.Template; Order = templateProvider.Order; Name = templateProvider.Name; } - public AttributeRouteModel([NotNull] AttributeRouteModel other) + public AttributeRouteModel(AttributeRouteModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + Attribute = other.Attribute; Name = other.Name; Order = other.Order; diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs index 568e7ef61b..124636b78f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs @@ -1,10 +1,10 @@ -// 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. +using System; using System.Linq; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc.ApplicationModels @@ -18,15 +18,20 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels _authorizationOptions = authorizationOptionsAccessor.Value; } - public int Order { get { return -1000 + 10; } } + public int Order { get { return -1000 + 10; } } - public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context) + public void OnProvidersExecuted(ApplicationModelProviderContext context) { // Intentionally empty. } - public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context) + public void OnProvidersExecuting(ApplicationModelProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + AuthorizationPolicy policy; foreach (var controllerModel in context.Result.Controllers) diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs index 27aa47be8f..376f131a31 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs @@ -1,6 +1,7 @@ // 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. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -8,7 +9,6 @@ using System.Reflection; using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public class ControllerModel : ICommonModel, IFilterModel, IApiExplorerModel { public ControllerModel( - [NotNull] TypeInfo controllerType, - [NotNull] IReadOnlyList attributes) + TypeInfo controllerType, + IReadOnlyList attributes) { + if (controllerType == null) + { + throw new ArgumentNullException(nameof(controllerType)); + } + + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + ControllerType = controllerType; Actions = new List(); @@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels ControllerProperties = new List(); } - public ControllerModel([NotNull] ControllerModel other) + public ControllerModel(ControllerModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + ControllerName = other.ControllerName; ControllerType = other.ControllerType; diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs index 7782f13bbd..ccd9316db9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs @@ -1,17 +1,15 @@ -// 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. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; @@ -36,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels } /// - public virtual void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context) + public virtual void OnProvidersExecuting(ApplicationModelProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var filter in _globalFilters) { context.Result.Filters.Add(filter); @@ -92,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels } /// - public virtual void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context) + public virtual void OnProvidersExecuted(ApplicationModelProviderContext context) { // Intentionally empty. } @@ -105,8 +108,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// A set of instances for the given controller or /// null if the does not represent a controller. /// - protected virtual IEnumerable BuildControllerModels([NotNull] TypeInfo typeInfo) + protected virtual IEnumerable BuildControllerModels(TypeInfo typeInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + var controllerModel = CreateControllerModel(typeInfo); yield return controllerModel; } @@ -116,8 +124,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// /// The . /// A for the given . - protected virtual ControllerModel CreateControllerModel([NotNull] TypeInfo typeInfo) + protected virtual ControllerModel CreateControllerModel(TypeInfo typeInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + // For attribute routes on a controller, we want want to support 'overriding' routes on a derived // class. So we need to walk up the hierarchy looking for the first class to define routes. // @@ -214,8 +227,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// /// The . /// A for the given . - protected virtual PropertyModel CreatePropertyModel([NotNull] PropertyInfo propertyInfo) + protected virtual PropertyModel CreatePropertyModel(PropertyInfo propertyInfo) { + if (propertyInfo == null) + { + throw new ArgumentNullException(nameof(propertyInfo)); + } + // CoreCLR returns IEnumerable from GetCustomAttributes - the OfType // is needed to so that the result of ToArray() is object var attributes = propertyInfo.GetCustomAttributes(inherit: true).OfType().ToArray(); @@ -239,9 +257,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// null if the does not represent an action. /// protected virtual IEnumerable BuildActionModels( - [NotNull] TypeInfo typeInfo, - [NotNull] MethodInfo methodInfo) + TypeInfo typeInfo, + MethodInfo methodInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + + if (methodInfo == null) + { + throw new ArgumentNullException(nameof(methodInfo)); + } + if (!IsAction(typeInfo, methodInfo)) { return Enumerable.Empty(); @@ -436,8 +464,18 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// /// Override this method to provide custom logic to determine which methods are considered actions. /// - protected virtual bool IsAction([NotNull] TypeInfo typeInfo, [NotNull] MethodInfo methodInfo) + protected virtual bool IsAction(TypeInfo typeInfo, MethodInfo methodInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + + if (methodInfo == null) + { + throw new ArgumentNullException(nameof(methodInfo)); + } + // The SpecialName bit is set to flag members that are treated in a special way by some compilers // (such as property accessors and operator overloading methods). if (methodInfo.IsSpecialName) @@ -500,9 +538,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// the action being created. /// protected virtual ActionModel CreateActionModel( - [NotNull] MethodInfo methodInfo, - [NotNull] IReadOnlyList attributes) + MethodInfo methodInfo, + IReadOnlyList attributes) { + if (methodInfo == null) + { + throw new ArgumentNullException(nameof(methodInfo)); + } + + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + var actionModel = new ActionModel(methodInfo, attributes); AddRange(actionModel.ActionConstraints, attributes.OfType()); @@ -558,8 +606,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// /// The . /// A for the given . - protected virtual ParameterModel CreateParameterModel([NotNull] ParameterInfo parameterInfo) + protected virtual ParameterModel CreateParameterModel(ParameterInfo parameterInfo) { + if (parameterInfo == null) + { + throw new ArgumentNullException(nameof(parameterInfo)); + } + // CoreCLR returns IEnumerable from GetCustomAttributes - the OfType // is needed to so that the result of ToArray() is object var attributes = parameterInfo.GetCustomAttributes(inherit: true).OfType().ToArray(); diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IActionModelConvention.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IActionModelConvention.cs index accf7488a7..c96101ccb8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IActionModelConvention.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IActionModelConvention.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApplicationModels { /// @@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Called to apply the convention to the . /// /// The . - void Apply([NotNull] ActionModel action); + void Apply(ActionModel action); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelConvention.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelConvention.cs index 0ffc15bf5f..f7a210fd79 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelConvention.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelConvention.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApplicationModels { /// @@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Called to apply the convention to the . /// /// The . - void Apply([NotNull] ApplicationModel application); + void Apply(ApplicationModel application); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelProvider.cs index bd7d7a2201..bade659e64 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IApplicationModelProvider.cs @@ -1,8 +1,6 @@ -// 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApplicationModels { /// @@ -35,12 +33,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Executed for the first pass of building. See . /// /// The . - void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context); + void OnProvidersExecuting(ApplicationModelProviderContext context); /// /// Executed for the second pass of building. See . /// /// The . - void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context); + void OnProvidersExecuted(ApplicationModelProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IControllerModelConvention.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IControllerModelConvention.cs index 0c4b6e1a60..9bf89b37c4 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IControllerModelConvention.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IControllerModelConvention.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApplicationModels { /// @@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Called to apply the convention to the . /// /// The . - void Apply([NotNull] ControllerModel controller); + void Apply(ControllerModel controller); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IParameterModelConvention.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IParameterModelConvention.cs index 42bd4df3ae..bfa3b11fc8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IParameterModelConvention.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/IParameterModelConvention.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ApplicationModels { /// @@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Called to apply the convention to the . /// /// The . - void Apply([NotNull] ParameterModel parameter); + void Apply(ParameterModel parameter); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ParameterModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ParameterModel.cs index afeccf4e58..5617886690 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ParameterModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ParameterModel.cs @@ -1,11 +1,11 @@ // 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. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -13,16 +13,31 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public class ParameterModel : ICommonModel, IBindingModel { public ParameterModel( - [NotNull] ParameterInfo parameterInfo, - [NotNull] IReadOnlyList attributes) + ParameterInfo parameterInfo, + IReadOnlyList attributes) { + if (parameterInfo == null) + { + throw new ArgumentNullException(nameof(parameterInfo)); + } + + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + ParameterInfo = parameterInfo; Properties = new Dictionary(); Attributes = new List(attributes); } - public ParameterModel([NotNull] ParameterModel other) + public ParameterModel(ParameterModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + Action = other.Action; Attributes = new List(other.Attributes); BindingInfo = other.BindingInfo == null ? null : new BindingInfo(other.BindingInfo); diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/PropertyModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/PropertyModel.cs index 85f460ae6d..707fea293a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/PropertyModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/PropertyModel.cs @@ -1,11 +1,11 @@ // 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. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { @@ -21,9 +21,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// The for the underlying property. /// Any attributes which are annotated on the property. public PropertyModel( - [NotNull] PropertyInfo propertyInfo, - [NotNull] IReadOnlyList attributes) + PropertyInfo propertyInfo, + IReadOnlyList attributes) { + if (propertyInfo == null) + { + throw new ArgumentNullException(nameof(propertyInfo)); + } + + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + PropertyInfo = propertyInfo; Properties = new Dictionary(); Attributes = new List(attributes); @@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels /// Creats a new instance of from a given . /// /// The which needs to be copied. - public PropertyModel([NotNull] PropertyModel other) + public PropertyModel(PropertyModel other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + Controller = other.Controller; Attributes = new List(other.Attributes); BindingInfo = BindingInfo == null ? null : new BindingInfo(other.BindingInfo); diff --git a/src/Microsoft.AspNet.Mvc.Core/BadRequestObjectResult.cs b/src/Microsoft.AspNet.Mvc.Core/BadRequestObjectResult.cs index 4bc0e869dd..bac4e59def 100644 --- a/src/Microsoft.AspNet.Mvc.Core/BadRequestObjectResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/BadRequestObjectResult.cs @@ -1,9 +1,9 @@ // 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. +using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,14 @@ namespace Microsoft.AspNet.Mvc /// Creates a new instance. /// /// containing the validation errors. - public BadRequestObjectResult([NotNull] ModelStateDictionary modelState) + public BadRequestObjectResult(ModelStateDictionary modelState) : base(new SerializableError(modelState)) { + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + StatusCode = StatusCodes.Status400BadRequest; } } diff --git a/src/Microsoft.AspNet.Mvc.Core/BindAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/BindAttribute.cs index 1a8556ca27..be9c8d03d5 100644 --- a/src/Microsoft.AspNet.Mvc.Core/BindAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/BindAttribute.cs @@ -8,7 +8,6 @@ using System.Reflection; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -46,8 +45,13 @@ namespace Microsoft.AspNet.Mvc /// The type which implements /// . /// - public BindAttribute([NotNull] Type predicateProviderType) + public BindAttribute(Type predicateProviderType) { + if (predicateProviderType == null) + { + throw new ArgumentNullException(nameof(predicateProviderType)); + } + if (!typeof(IPropertyBindingPredicateProvider).GetTypeInfo() .IsAssignableFrom(predicateProviderType.GetTypeInfo())) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs index 59cd1c552e..d23db75a3b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs @@ -6,7 +6,6 @@ using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder { @@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Builder /// The . /// This method only supports attribute routing. To add conventional routes use /// . - public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app) + public static IApplicationBuilder UseMvc(this IApplicationBuilder app) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + return app.UseMvc(routes => { }); @@ -36,8 +40,13 @@ namespace Microsoft.AspNet.Builder /// /// The . /// The . - public static IApplicationBuilder UseMvcWithDefaultRoute([NotNull] this IApplicationBuilder app) + public static IApplicationBuilder UseMvcWithDefaultRoute(this IApplicationBuilder app) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + return app.UseMvc(routes => { routes.MapRoute( @@ -53,9 +62,19 @@ namespace Microsoft.AspNet.Builder /// A callback to configure MVC routes. /// The . public static IApplicationBuilder UseMvc( - [NotNull] this IApplicationBuilder app, - [NotNull] Action configureRoutes) + this IApplicationBuilder app, + Action configureRoutes) { + if (app == null) + { + throw new ArgumentNullException(nameof(app)); + } + + if (configureRoutes == null) + { + throw new ArgumentNullException(nameof(configureRoutes)); + } + // Verify if AddMvc was done before calling UseMvc // We use the MvcMarkerService to make sure if all the services were added. MvcServicesHelper.ThrowIfMvcNotRegistered(app.ApplicationServices); diff --git a/src/Microsoft.AspNet.Mvc.Core/ChallengeResult.cs b/src/Microsoft.AspNet.Mvc.Core/ChallengeResult.cs index 8f1fa10735..1057916ac8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ChallengeResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ChallengeResult.cs @@ -1,10 +1,10 @@ // 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. +using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Http.Authentication; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -45,8 +45,13 @@ namespace Microsoft.AspNet.Mvc public AuthenticationProperties Properties { get; set; } - public override async Task ExecuteResultAsync([NotNull] ActionContext context) + public override async Task ExecuteResultAsync(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var auth = context.HttpContext.Authentication; if (AuthenticationSchemes.Count > 0) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ConsumesAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/ConsumesAttribute.cs index 3763d6162f..177c090e7e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ConsumesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ConsumesAttribute.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -24,8 +23,13 @@ namespace Microsoft.AspNet.Mvc /// /// Creates a new instance of . /// - public ConsumesAttribute([NotNull] string contentType, params string[] otherContentTypes) + public ConsumesAttribute(string contentType, params string[] otherContentTypes) { + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + ContentTypes = GetContentTypes(contentType, otherContentTypes); } @@ -38,8 +42,13 @@ namespace Microsoft.AspNet.Mvc public IList ContentTypes { get; set; } /// - public void OnResourceExecuting([NotNull] ResourceExecutingContext context) + public void OnResourceExecuting(ResourceExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Only execute if the current filter is the one which is closest to the action. // Ignore all other filters. This is to ensure we have a overriding behavior. if (IsApplicable(context.ActionDescriptor)) @@ -58,8 +67,12 @@ namespace Microsoft.AspNet.Mvc } /// - public void OnResourceExecuted([NotNull] ResourceExecutedContext context) + public void OnResourceExecuted(ResourceExecutedContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } public bool Accept(ActionConstraintContext context) diff --git a/src/Microsoft.AspNet.Mvc.Core/ContentResult.cs b/src/Microsoft.AspNet.Mvc.Core/ContentResult.cs index 6beb8b68df..224a3c211c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ContentResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ContentResult.cs @@ -1,12 +1,12 @@ // 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. +using System; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Mvc.Internal; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -33,8 +33,13 @@ namespace Microsoft.AspNet.Mvc /// public int? StatusCode { get; set; } - public override Task ExecuteResultAsync([NotNull] ActionContext context) + public override Task ExecuteResultAsync(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var response = context.HttpContext.Response; var contentTypeHeader = ContentType; diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionDescriptorProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionDescriptorProvider.cs index 44bab034b3..c7a8565789 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionDescriptorProvider.cs @@ -1,11 +1,11 @@ // 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. +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.ApplicationModels; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc.Controllers @@ -17,10 +17,25 @@ namespace Microsoft.AspNet.Mvc.Controllers private readonly IEnumerable _conventions; public ControllerActionDescriptorProvider( - [NotNull] IControllerTypeProvider controllerTypeProvider, - [NotNull] IEnumerable applicationModelProviders, - [NotNull] IOptions optionsAccessor) + IControllerTypeProvider controllerTypeProvider, + IEnumerable applicationModelProviders, + IOptions optionsAccessor) { + if (controllerTypeProvider == null) + { + throw new ArgumentNullException(nameof(controllerTypeProvider)); + } + + if (applicationModelProviders == null) + { + throw new ArgumentNullException(nameof(applicationModelProviders)); + } + + if (optionsAccessor == null) + { + throw new ArgumentNullException(nameof(optionsAccessor)); + } + _controllerTypeProvider = controllerTypeProvider; _applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray(); _conventions = optionsAccessor.Value.Conventions; @@ -32,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers } /// - public void OnProvidersExecuting ([NotNull] ActionDescriptorProviderContext context) + public void OnProvidersExecuting(ActionDescriptorProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var descriptor in GetDescriptors()) { context.Results.Add(descriptor); @@ -41,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.Controllers } /// - public void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context) + public void OnProvidersExecuted(ActionDescriptorProviderContext context) { } @@ -62,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.Controllers _applicationModelProviders[i].OnProvidersExecuting(context); } - for (var i = _applicationModelProviders.Length - 1 ; i >= 0; i--) + for (var i = _applicationModelProviders.Length - 1; i >= 0; i--) { _applicationModelProviders[i].OnProvidersExecuted(context); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs index a7d96f1e73..b6f0af1ed7 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs @@ -25,19 +25,19 @@ namespace Microsoft.AspNet.Mvc.Controllers private readonly IControllerActionArgumentBinder _argumentBinder; public ControllerActionInvoker( - [NotNull] ActionContext actionContext, - [NotNull] IReadOnlyList filterProviders, - [NotNull] IControllerFactory controllerFactory, - [NotNull] ControllerActionDescriptor descriptor, - [NotNull] IReadOnlyList inputFormatters, - [NotNull] IReadOnlyList outputFormatters, - [NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder, - [NotNull] IReadOnlyList modelBinders, - [NotNull] IReadOnlyList modelValidatorProviders, - [NotNull] IReadOnlyList valueProviderFactories, - [NotNull] IActionBindingContextAccessor actionBindingContextAccessor, - [NotNull] ILogger logger, - [NotNull] TelemetrySource telemetry, + ActionContext actionContext, + IReadOnlyList filterProviders, + IControllerFactory controllerFactory, + ControllerActionDescriptor descriptor, + IReadOnlyList inputFormatters, + IReadOnlyList outputFormatters, + IControllerActionArgumentBinder controllerActionArgumentBinder, + IReadOnlyList modelBinders, + IReadOnlyList modelValidatorProviders, + IReadOnlyList valueProviderFactories, + IActionBindingContextAccessor actionBindingContextAccessor, + ILogger logger, + TelemetrySource telemetry, int maxModelValidationErrors) : base( actionContext, @@ -52,6 +52,71 @@ namespace Microsoft.AspNet.Mvc.Controllers telemetry, maxModelValidationErrors) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (filterProviders == null) + { + throw new ArgumentNullException(nameof(filterProviders)); + } + + if (controllerFactory == null) + { + throw new ArgumentNullException(nameof(controllerFactory)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (outputFormatters == null) + { + throw new ArgumentNullException(nameof(outputFormatters)); + } + + if (controllerActionArgumentBinder == null) + { + throw new ArgumentNullException(nameof(controllerActionArgumentBinder)); + } + + if (modelBinders == null) + { + throw new ArgumentNullException(nameof(modelBinders)); + } + + if (modelValidatorProviders == null) + { + throw new ArgumentNullException(nameof(modelValidatorProviders)); + } + + if (valueProviderFactories == null) + { + throw new ArgumentNullException(nameof(valueProviderFactories)); + } + + if (actionBindingContextAccessor == null) + { + throw new ArgumentNullException(nameof(actionBindingContextAccessor)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (telemetry == null) + { + throw new ArgumentNullException(nameof(telemetry)); + } + _descriptor = descriptor; _controllerFactory = controllerFactory; _argumentBinder = controllerActionArgumentBinder; @@ -95,12 +160,27 @@ namespace Microsoft.AspNet.Mvc.Controllers ActionContext context, ActionBindingContext bindingContext) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + return _argumentBinder.BindActionArgumentsAsync(context, bindingContext, Instance); } // Marking as internal for Unit Testing purposes. - internal static IActionResult CreateActionResult([NotNull] Type declaredReturnType, object actionReturnValue) + internal static IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue) { + if (declaredReturnType == null) + { + throw new ArgumentNullException(nameof(declaredReturnType)); + } + // optimize common path var actionResult = actionReturnValue as IActionResult; if (actionResult != null) diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs index 27f54455f3..48a54733fb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs @@ -1,6 +1,7 @@ // 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. +using System; using System.Collections.Generic; using System.Diagnostics.Tracing; using System.Linq; @@ -10,7 +11,6 @@ using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; @@ -60,32 +60,37 @@ namespace Microsoft.AspNet.Mvc.Controllers } /// - public void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context) + public void OnProvidersExecuting(ActionInvokerProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor; if (actionDescriptor != null) { context.Result = new ControllerActionInvoker( - context.ActionContext, - _filterProviders, - _controllerFactory, - actionDescriptor, - _inputFormatters, - _outputFormatters, - _argumentBinder, - _modelBinders, - _modelValidatorProviders, - _valueProviderFactories, - _actionBindingContextAccessor, - _logger, - _telemetry, - _maxModelValidationErrors); + context.ActionContext, + _filterProviders, + _controllerFactory, + actionDescriptor, + _inputFormatters, + _outputFormatters, + _argumentBinder, + _modelBinders, + _modelValidatorProviders, + _valueProviderFactories, + _actionBindingContextAccessor, + _logger, + _telemetry, + _maxModelValidationErrors); } } /// - public void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context) + public void OnProvidersExecuted(ActionInvokerProviderContext context) { } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActionArgumentBinder.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActionArgumentBinder.cs index 40c2e1091b..3548db49da 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActionArgumentBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActionArgumentBinder.cs @@ -40,6 +40,21 @@ namespace Microsoft.AspNet.Mvc.Controllers ActionBindingContext actionBindingContext, object controller) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (actionBindingContext == null) + { + throw new ArgumentNullException(nameof(actionBindingContext)); + } + + if (controller == null) + { + throw new ArgumentNullException(nameof(controller)); + } + var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor; if (actionDescriptor == null) { @@ -69,10 +84,25 @@ namespace Microsoft.AspNet.Mvc.Controllers } public async Task BindModelAsync( - [NotNull] ParameterDescriptor parameter, - [NotNull] ModelStateDictionary modelState, - [NotNull] OperationBindingContext operationContext) + ParameterDescriptor parameter, + ModelStateDictionary modelState, + OperationBindingContext operationContext) { + if (parameter == null) + { + throw new ArgumentNullException(nameof(parameter)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (operationContext == null) + { + throw new ArgumentNullException(nameof(operationContext)); + } + var metadata = _modelMetadataProvider.GetMetadataForType(parameter.ParameterType); var modelBindingContext = ModelBindingContext.CreateBindingContext( operationContext, diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActivator.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActivator.cs index 972b615286..2499f21977 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActivator.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerActivator.cs @@ -3,8 +3,6 @@ using System; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -24,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Controllers _typeActivatorCache = typeActivatorCache; } /// - public virtual object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType) + public virtual object Create(ActionContext actionContext, Type controllerType) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (controllerType == null) + { + throw new ArgumentNullException(nameof(controllerType)); + } + var serviceProvider = actionContext.HttpContext.RequestServices; return _typeActivatorCache.CreateInstance(serviceProvider, controllerType); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerFactory.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerFactory.cs index 63b431bc3c..0fbd198c8f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerFactory.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -48,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers } /// - public virtual object CreateController([NotNull] ActionContext actionContext) + public virtual object CreateController(ActionContext actionContext) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor; if (actionDescriptor == null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerTypeProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerTypeProvider.cs index d67b2e0168..9df22d69b7 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerTypeProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/DefaultControllerTypeProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -48,9 +47,19 @@ namespace Microsoft.AspNet.Mvc.Controllers /// The set of candidate assemblies. /// true if the is a controller. Otherwise false. protected internal virtual bool IsController( - [NotNull] TypeInfo typeInfo, - [NotNull] ISet candidateAssemblies) + TypeInfo typeInfo, + ISet candidateAssemblies) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + + if (candidateAssemblies == null) + { + throw new ArgumentNullException(nameof(candidateAssemblies)); + } + if (!typeInfo.IsClass) { return false; diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs index 9263427cb8..afd9b8637d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs @@ -16,7 +16,6 @@ using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Controllers @@ -62,18 +61,68 @@ namespace Microsoft.AspNet.Mvc.Controllers "Request was short circuited at result filter '{ResultFilter}'."; public FilterActionInvoker( - [NotNull] ActionContext actionContext, - [NotNull] IReadOnlyList filterProviders, - [NotNull] IReadOnlyList inputFormatters, - [NotNull] IReadOnlyList outputFormatters, - [NotNull] IReadOnlyList modelBinders, - [NotNull] IReadOnlyList modelValidatorProviders, - [NotNull] IReadOnlyList valueProviderFactories, - [NotNull] IActionBindingContextAccessor actionBindingContextAccessor, - [NotNull] ILogger logger, - [NotNull] TelemetrySource telemetry, + ActionContext actionContext, + IReadOnlyList filterProviders, + IReadOnlyList inputFormatters, + IReadOnlyList outputFormatters, + IReadOnlyList modelBinders, + IReadOnlyList modelValidatorProviders, + IReadOnlyList valueProviderFactories, + IActionBindingContextAccessor actionBindingContextAccessor, + ILogger logger, + TelemetrySource telemetry, int maxModelValidationErrors) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (filterProviders == null) + { + throw new ArgumentNullException(nameof(filterProviders)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (outputFormatters == null) + { + throw new ArgumentNullException(nameof(outputFormatters)); + } + + if (modelBinders == null) + { + throw new ArgumentNullException(nameof(modelBinders)); + } + + if (modelValidatorProviders == null) + { + throw new ArgumentNullException(nameof(modelValidatorProviders)); + } + + if (valueProviderFactories == null) + { + throw new ArgumentNullException(nameof(valueProviderFactories)); + } + + if (actionBindingContextAccessor == null) + { + throw new ArgumentNullException(nameof(actionBindingContextAccessor)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (telemetry == null) + { + throw new ArgumentNullException(nameof(telemetry)); + } + ActionContext = actionContext; _filterProviders = filterProviders; @@ -120,8 +169,8 @@ namespace Microsoft.AspNet.Mvc.Controllers protected abstract Task InvokeActionAsync(ActionExecutingContext actionExecutingContext); protected abstract Task> BindActionArgumentsAsync( - [NotNull] ActionContext context, - [NotNull] ActionBindingContext bindingContext); + ActionContext context, + ActionBindingContext bindingContext); public virtual async Task InvokeAsync() { diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/IControllerActionArgumentBinder.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/IControllerActionArgumentBinder.cs index bbc3b63ef2..081c0d3377 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/IControllerActionArgumentBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/IControllerActionArgumentBinder.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -21,8 +20,8 @@ namespace Microsoft.AspNet.Mvc.Controllers /// The . /// The controller object which contains the action. Task> BindActionArgumentsAsync( - [NotNull] ActionContext context, - [NotNull] ActionBindingContext bindingContext, - [NotNull] object controller); + ActionContext context, + ActionBindingContext bindingContext, + object controller); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ServiceBasedControllerActivator.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ServiceBasedControllerActivator.cs index 6a6bf1262f..5ad891c85b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ServiceBasedControllerActivator.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ServiceBasedControllerActivator.cs @@ -3,7 +3,6 @@ using System; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -14,8 +13,18 @@ namespace Microsoft.AspNet.Mvc.Controllers public class ServiceBasedControllerActivator : IControllerActivator { /// - public object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType) + public object Create(ActionContext actionContext, Type controllerType) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (controllerType == null) + { + throw new ArgumentNullException(nameof(controllerType)); + } + return actionContext.HttpContext.RequestServices.GetRequiredService(controllerType); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/StaticControllerTypeProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/StaticControllerTypeProvider.cs index d221df7d41..7dd16e692b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/StaticControllerTypeProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/StaticControllerTypeProvider.cs @@ -1,10 +1,10 @@ // 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. +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Controllers { @@ -25,8 +25,13 @@ namespace Microsoft.AspNet.Mvc.Controllers /// Initializes a new instance of . /// /// The sequence of controller . - public StaticControllerTypeProvider([NotNull] IEnumerable controllerTypes) + public StaticControllerTypeProvider(IEnumerable controllerTypes) { + if (controllerTypes == null) + { + throw new ArgumentNullException(nameof(controllerTypes)); + } + ControllerTypes = new List(controllerTypes); } diff --git a/src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs b/src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs index 447f0b2ac8..fda06dfbeb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/CreatedAtActionResult.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Core; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; @@ -59,16 +58,21 @@ namespace Microsoft.AspNet.Mvc public IDictionary RouteValues { get; set; } /// - protected override void OnFormatting([NotNull] ActionContext context) + protected override void OnFormatting(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var request = context.HttpContext.Request; var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService(); var url = urlHelper.Action( - ActionName, - ControllerName, - RouteValues, - request.Scheme, + ActionName, + ControllerName, + RouteValues, + request.Scheme, request.Host.ToUriComponent()); if (string.IsNullOrEmpty(url)) diff --git a/src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs b/src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs index 0c6b052340..b3445d9d8b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/CreatedAtRouteResult.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Core; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; @@ -62,8 +61,13 @@ namespace Microsoft.AspNet.Mvc public IDictionary RouteValues { get; set; } /// - protected override void OnFormatting([NotNull] ActionContext context) + protected override void OnFormatting(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService(); var url = urlHelper.Link(RouteName, RouteValues); diff --git a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs index 68c1476504..aa54c6bdcb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -21,9 +20,14 @@ namespace Microsoft.AspNet.Mvc /// /// The location at which the content has been created. /// The value to format in the entity body. - public CreatedResult([NotNull] string location, object value) + public CreatedResult(string location, object value) : base(value) { + if (location == null) + { + throw new ArgumentNullException(nameof(location)); + } + Location = location; StatusCode = StatusCodes.Status201Created; } @@ -34,9 +38,14 @@ namespace Microsoft.AspNet.Mvc /// /// The location at which the content has been created. /// The value to format in the entity body. - public CreatedResult([NotNull] Uri location, object value) + public CreatedResult(Uri location, object value) : base(value) { + if (location == null) + { + throw new ArgumentNullException(nameof(location)); + } + if (location.IsAbsoluteUri) { Location = location.AbsoluteUri; @@ -70,8 +79,13 @@ namespace Microsoft.AspNet.Mvc } /// - protected override void OnFormatting([NotNull] ActionContext context) + protected override void OnFormatting(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + context.HttpContext.Response.Headers[HeaderNames.Location] = Location; } } diff --git a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs index 38ccd4831f..04d307183d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.ApplicationModels; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { @@ -20,9 +20,19 @@ namespace Microsoft.Framework.DependencyInjection /// The which needs to be /// added. public static void Add( - [NotNull] this IList conventions, - [NotNull] IControllerModelConvention controllerModelConvention) + this IList conventions, + IControllerModelConvention controllerModelConvention) { + if (conventions == null) + { + throw new ArgumentNullException(nameof(conventions)); + } + + if (controllerModelConvention == null) + { + throw new ArgumentNullException(nameof(controllerModelConvention)); + } + conventions.Add(new ControllerApplicationModelConvention(controllerModelConvention)); } @@ -49,14 +59,24 @@ namespace Microsoft.Framework.DependencyInjection /// /// The action convention to be applied on all actions /// in the application. - public ActionApplicationModelConvention([NotNull] IActionModelConvention actionModelConvention) + public ActionApplicationModelConvention(IActionModelConvention actionModelConvention) { + if (actionModelConvention == null) + { + throw new ArgumentNullException(nameof(actionModelConvention)); + } + _actionModelConvention = actionModelConvention; } /// - public void Apply([NotNull] ApplicationModel application) + public void Apply(ApplicationModel application) { + if (application == null) + { + throw new ArgumentNullException(nameof(application)); + } + foreach (var controller in application.Controllers) { foreach (var action in controller.Actions) @@ -76,14 +96,24 @@ namespace Microsoft.Framework.DependencyInjection /// /// The controller convention to be applied on all controllers /// in the application. - public ControllerApplicationModelConvention([NotNull] IControllerModelConvention controllerConvention) + public ControllerApplicationModelConvention(IControllerModelConvention controllerConvention) { + if (controllerConvention == null) + { + throw new ArgumentNullException(nameof(controllerConvention)); + } + _controllerModelConvention = controllerConvention; } /// - public void Apply([NotNull] ApplicationModel application) + public void Apply(ApplicationModel application) { + if (application == null) + { + throw new ArgumentNullException(nameof(application)); + } + foreach (var controller in application.Controllers) { _controllerModelConvention.Apply(controller); diff --git a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcBuilderExtensions.cs index a0f9e56983..895971043b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcBuilderExtensions.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -7,7 +7,6 @@ using System.Reflection; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { @@ -23,17 +22,37 @@ namespace Microsoft.Framework.DependencyInjection /// An . /// The . public static IMvcBuilder AddMvcOptions( - [NotNull] this IMvcBuilder builder, - [NotNull] Action setupAction) + this IMvcBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure(setupAction); return builder; } public static IMvcBuilder AddFormatterMappings( - [NotNull] this IMvcBuilder builder, - [NotNull] Action setupAction) + this IMvcBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure((options) => setupAction(options.FormatterMappings)); return builder; } @@ -47,9 +66,19 @@ namespace Microsoft.Framework.DependencyInjection /// and used for controller discovery. /// The . public static IMvcBuilder AddControllersAsServices( - [NotNull] this IMvcBuilder builder, - [NotNull] IEnumerable controllerTypes) + this IMvcBuilder builder, + IEnumerable controllerTypes) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (controllerTypes == null) + { + throw new ArgumentNullException(nameof(controllerTypes)); + } + ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes); return builder; } @@ -62,9 +91,19 @@ namespace Microsoft.Framework.DependencyInjection /// Assemblies to scan. /// The . public static IMvcBuilder AddControllersAsServices( - [NotNull] this IMvcBuilder builder, - [NotNull] IEnumerable controllerAssemblies) + this IMvcBuilder builder, + IEnumerable controllerAssemblies) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (controllerAssemblies == null) + { + throw new ArgumentNullException(nameof(controllerAssemblies)); + } + ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs index 698216b1e6..f892dcbc3f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Internal; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { @@ -23,9 +22,19 @@ namespace Microsoft.Framework.DependencyInjection /// An . /// The . public static IMvcCoreBuilder AddMvcOptions( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] Action setupAction) + this IMvcCoreBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure(setupAction); return builder; } @@ -94,9 +103,19 @@ namespace Microsoft.Framework.DependencyInjection /// and used for controller discovery. /// The . public static IMvcCoreBuilder AddControllersAsServices( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] IEnumerable controllerTypes) + this IMvcCoreBuilder builder, + IEnumerable controllerTypes) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (controllerTypes == null) + { + throw new ArgumentNullException(nameof(controllerTypes)); + } + ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes); return builder; } @@ -109,9 +128,19 @@ namespace Microsoft.Framework.DependencyInjection /// Assemblies to scan. /// The . public static IMvcCoreBuilder AddControllersAsServices( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] IEnumerable controllerAssemblies) + this IMvcCoreBuilder builder, + IEnumerable controllerAssemblies) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (controllerAssemblies == null) + { + throw new ArgumentNullException(nameof(controllerAssemblies)); + } + ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs index a296bf438f..433d49d707 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -16,22 +16,31 @@ using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.Framework.DependencyInjection { public static class MvcCoreServiceCollectionExtensions { - public static IMvcCoreBuilder AddMvcCore([NotNull] this IServiceCollection services) + public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + return AddMvcCore(services, setupAction: null); } public static IMvcCoreBuilder AddMvcCore( - [NotNull] this IServiceCollection services, + this IServiceCollection services, Action setupAction) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + ConfigureDefaultServices(services); AddMvcCoreServices(services); diff --git a/src/Microsoft.AspNet.Mvc.Core/EmptyResult.cs b/src/Microsoft.AspNet.Mvc.Core/EmptyResult.cs index 26166d2d19..c190402221 100644 --- a/src/Microsoft.AspNet.Mvc.Core/EmptyResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/EmptyResult.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc { /// @@ -11,15 +9,8 @@ namespace Microsoft.AspNet.Mvc /// public class EmptyResult : ActionResult { - private static readonly EmptyResult _singleton = new EmptyResult(); - - internal static EmptyResult Instance - { - get { return _singleton; } - } - /// - public override void ExecuteResult([NotNull] ActionContext context) + public override void ExecuteResult(ActionContext context) { } } diff --git a/src/Microsoft.AspNet.Mvc.Core/FileContentResult.cs b/src/Microsoft.AspNet.Mvc.Core/FileContentResult.cs index 9a2befb433..558d76eaaa 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FileContentResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FileContentResult.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -26,9 +25,17 @@ namespace Microsoft.AspNet.Mvc /// /// The bytes that represent the file contents. /// The Content-Type header of the response. - public FileContentResult([NotNull] byte[] fileContents, [NotNull] string contentType) + public FileContentResult(byte[] fileContents, string contentType) : this(fileContents, new MediaTypeHeaderValue(contentType)) { + if (fileContents == null) + { + throw new ArgumentNullException(nameof(fileContents)); + } + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } } /// @@ -38,9 +45,19 @@ namespace Microsoft.AspNet.Mvc /// /// The bytes that represent the file contents. /// The Content-Type header of the response. - public FileContentResult([NotNull] byte[] fileContents, [NotNull] MediaTypeHeaderValue contentType) + public FileContentResult(byte[] fileContents, MediaTypeHeaderValue contentType) : base(contentType) { + if (fileContents == null) + { + throw new ArgumentNullException(nameof(fileContents)); + } + + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + FileContents = fileContents; } diff --git a/src/Microsoft.AspNet.Mvc.Core/FileResult.cs b/src/Microsoft.AspNet.Mvc.Core/FileResult.cs index 6e7925d74f..84db886e74 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FileResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FileResult.cs @@ -1,10 +1,10 @@ // 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. +using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -22,9 +22,13 @@ namespace Microsoft.AspNet.Mvc /// the provided . /// /// The Content-Type header of the response. - protected FileResult([NotNull] string contentType) + protected FileResult(string contentType) : this(new MediaTypeHeaderValue(contentType)) { + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } } /// @@ -32,8 +36,13 @@ namespace Microsoft.AspNet.Mvc /// the provided . /// /// The Content-Type header of the response. - protected FileResult([NotNull] MediaTypeHeaderValue contentType) + protected FileResult(MediaTypeHeaderValue contentType) { + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + ContentType = contentType; } @@ -52,8 +61,13 @@ namespace Microsoft.AspNet.Mvc } /// - public override Task ExecuteResultAsync([NotNull] ActionContext context) + public override Task ExecuteResultAsync(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var response = context.HttpContext.Response; response.ContentType = ContentType.ToString(); diff --git a/src/Microsoft.AspNet.Mvc.Core/FileStreamResult.cs b/src/Microsoft.AspNet.Mvc.Core/FileStreamResult.cs index 08bded14b8..6533c49826 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FileStreamResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FileStreamResult.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -30,7 +29,7 @@ namespace Microsoft.AspNet.Mvc /// /// The stream with the file. /// The Content-Type header of the response. - public FileStreamResult([NotNull] Stream fileStream, [NotNull] string contentType) + public FileStreamResult(Stream fileStream, string contentType) : this(fileStream, new MediaTypeHeaderValue(contentType)) { } @@ -42,9 +41,19 @@ namespace Microsoft.AspNet.Mvc /// /// The stream with the file. /// The Content-Type header of the response. - public FileStreamResult([NotNull] Stream fileStream, [NotNull] MediaTypeHeaderValue contentType) + public FileStreamResult(Stream fileStream, MediaTypeHeaderValue contentType) : base(contentType) { + if (fileStream == null) + { + throw new ArgumentNullException(nameof(fileStream)); + } + + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + FileStream = fileStream; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs index a1aaaacfaa..51c92b19f6 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -13,18 +12,28 @@ namespace Microsoft.AspNet.Mvc.Filters { public int Order { get; set; } - public virtual void OnActionExecuting([NotNull] ActionExecutingContext context) + public virtual void OnActionExecuting(ActionExecutingContext context) { } - public virtual void OnActionExecuted([NotNull] ActionExecutedContext context) + public virtual void OnActionExecuted(ActionExecutedContext context) { } public virtual async Task OnActionExecutionAsync( - [NotNull] ActionExecutingContext context, - [NotNull] ActionExecutionDelegate next) + ActionExecutingContext context, + ActionExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + OnActionExecuting(context); if (context.Result == null) { @@ -32,18 +41,28 @@ namespace Microsoft.AspNet.Mvc.Filters } } - public virtual void OnResultExecuting([NotNull] ResultExecutingContext context) + public virtual void OnResultExecuting(ResultExecutingContext context) { } - public virtual void OnResultExecuted([NotNull] ResultExecutedContext context) + public virtual void OnResultExecuted(ResultExecutedContext context) { } public virtual async Task OnResultExecutionAsync( - [NotNull] ResultExecutingContext context, - [NotNull] ResultExecutionDelegate next) + ResultExecutingContext context, + ResultExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + OnResultExecuting(context); if (!context.Cancel) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterAttribute.cs index 6d74c83ffa..af50f99d07 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizationFilterAttribute.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -15,23 +14,38 @@ namespace Microsoft.AspNet.Mvc.Filters { public int Order { get; set; } - public virtual Task OnAuthorizationAsync([NotNull] AuthorizationContext context) + public virtual Task OnAuthorizationAsync(AuthorizationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + OnAuthorization(context); return TaskCache.CompletedTask; } - public virtual void OnAuthorization([NotNull] AuthorizationContext context) + public virtual void OnAuthorization(AuthorizationContext context) { } - protected virtual bool HasAllowAnonymous([NotNull] AuthorizationContext context) + protected virtual bool HasAllowAnonymous(AuthorizationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return context.Filters.Any(item => item is IAllowAnonymous); } - protected virtual void Fail([NotNull] AuthorizationContext context) + protected virtual void Fail(AuthorizationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + context.Result = new HttpUnauthorizedResult(); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs index cae4051ef4..6490265efc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/AuthorizeFilter.cs @@ -1,6 +1,7 @@ // 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. +using System; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; @@ -19,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// Authorize filter for a specific policy. /// /// Authorization policy to be used. - public AuthorizeFilter([NotNull] AuthorizationPolicy policy) + public AuthorizeFilter(AuthorizationPolicy policy) { + if (policy == null) + { + throw new ArgumentNullException(nameof(policy)); + } + Policy = policy; } @@ -30,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Filters public AuthorizationPolicy Policy { get; private set; } /// - public virtual async Task OnAuthorizationAsync([NotNull] Filters.AuthorizationContext context) + public virtual async Task OnAuthorizationAsync(Filters.AuthorizationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Build a ClaimsPrincipal with the Policy's required authentication types if (Policy.ActiveAuthenticationSchemes != null && Policy.ActiveAuthenticationSchemes.Any()) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerActionFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerActionFilter.cs index 7eb2ddb4f7..140923606a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerActionFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerActionFilter.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters /// public async Task OnActionExecutionAsync( - [NotNull] ActionExecutingContext context, - [NotNull] ActionExecutionDelegate next) + ActionExecutingContext context, + ActionExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + var controller = context.Controller; if (controller == null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerResultFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerResultFilter.cs index 56c9e6205b..e5c91200db 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerResultFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ControllerResultFilter.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters /// public async Task OnResultExecutionAsync( - [NotNull] ResultExecutingContext context, - [NotNull] ResultExecutionDelegate next) + ResultExecutingContext context, + ResultExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + var controller = context.Controller; if (controller == null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs index 0100367a14..09aada7670 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/DefaultFilterProvider.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Filters } /// - public void OnProvidersExecuting([NotNull] FilterProviderContext context) + public void OnProvidersExecuting(FilterProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (context.ActionContext.ActionDescriptor.FilterDescriptors != null) { // Perf: Avoid allocations @@ -29,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Filters } /// - public void OnProvidersExecuted([NotNull] FilterProviderContext context) + public void OnProvidersExecuted(FilterProviderContext context) { } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterAttribute.cs index 8f15789e03..fab99f2b8c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ExceptionFilterAttribute.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -13,13 +12,18 @@ namespace Microsoft.AspNet.Mvc.Filters { public int Order { get; set; } - public virtual Task OnExceptionAsync([NotNull] ExceptionContext context) + public virtual Task OnExceptionAsync(ExceptionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + OnException(context); return TaskCache.CompletedTask; } - public virtual void OnException([NotNull] ExceptionContext context) + public virtual void OnException(ExceptionContext context) { } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterCollection.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterCollection.cs index a4ff3bb3d3..2e06dfa17d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterCollection.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterCollection.cs @@ -1,11 +1,10 @@ -// 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. using System; using System.Collections.ObjectModel; using System.Reflection; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// . /// Use to register a service as a filter. /// - public IFilterMetadata Add([NotNull] Type filterType) + public IFilterMetadata Add(Type filterType) { + if (filterType == null) + { + throw new ArgumentNullException(nameof(filterType)); + } + return Add(filterType, order: 0); } @@ -37,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// . /// Use to register a service as a filter. /// - public IFilterMetadata Add([NotNull] Type filterType, int order) + public IFilterMetadata Add(Type filterType, int order) { + if (filterType == null) + { + throw new ArgumentNullException(nameof(filterType)); + } + if (!typeof(IFilterMetadata).IsAssignableFrom(filterType)) { var message = Resources.FormatTypeMustDeriveFromType( @@ -62,8 +71,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// to register a service that will be created via /// type activation. /// - public IFilterMetadata AddService([NotNull] Type filterType) + public IFilterMetadata AddService(Type filterType) { + if (filterType == null) + { + throw new ArgumentNullException(nameof(filterType)); + } + return AddService(filterType, order: 0); } @@ -78,8 +92,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// to register a service that will be created via /// type activation. /// - public IFilterMetadata AddService([NotNull] Type filterType, int order) + public IFilterMetadata AddService(Type filterType, int order) { + if (filterType == null) + { + throw new ArgumentNullException(nameof(filterType)); + } + if (!typeof(IFilterMetadata).GetTypeInfo().IsAssignableFrom(filterType.GetTypeInfo())) { var message = Resources.FormatTypeMustDeriveFromType( diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs index 99e593d83f..135c07942e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters get { return _comparer; } } - public int Compare([NotNull]FilterDescriptor x, [NotNull]FilterDescriptor y) + public int Compare(FilterDescriptor x, FilterDescriptor y) { + if (x == null) + { + throw new ArgumentNullException(nameof(x)); + } + + if (y == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.Order == y.Order) { return x.Scope.CompareTo(y.Scope); diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterItemOrderComparer.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterItemOrderComparer.cs index bcdf75efa0..2d861e6252 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/FilterItemOrderComparer.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/FilterItemOrderComparer.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters get { return _comparer; } } - public int Compare([NotNull] FilterItem x, [NotNull] FilterItem y) + public int Compare(FilterItem x, FilterItem y) { + if (x == null) + { + throw new ArgumentNullException(nameof(x)); + } + + if (y == null) + { + throw new ArgumentNullException(nameof(y)); + } + return FilterDescriptorOrderComparer.Comparer.Compare(x.Descriptor, y.Descriptor); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ResponseCacheFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ResponseCacheFilter.cs index 1f5d8686ec..8c809db505 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ResponseCacheFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ResponseCacheFilter.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.Linq; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc.Filters @@ -74,8 +73,13 @@ namespace Microsoft.AspNet.Mvc.Filters } // - public void OnActionExecuting([NotNull] ActionExecutingContext context) + public void OnActionExecuting(ActionExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // If there are more filters which can override the values written by this filter, // then skip execution of this filter. if (IsOverridden(context)) @@ -137,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.Filters CultureInfo.InvariantCulture, "{0}{1}max-age={2}", cacheControlValue, - cacheControlValue != null? "," : null, + cacheControlValue != null ? "," : null, Duration); if (cacheControlValue != null) @@ -148,13 +152,18 @@ namespace Microsoft.AspNet.Mvc.Filters } // - public void OnActionExecuted([NotNull]ActionExecutedContext context) + public void OnActionExecuted(ActionExecutedContext context) { } // internal for Unit Testing purposes. - internal bool IsOverridden([NotNull] ActionExecutingContext context) + internal bool IsOverridden(ActionExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Return true if there are any filters which are after the current filter. In which case the current // filter should be skipped. return context.Filters.OfType().Last() != this; diff --git a/src/Microsoft.AspNet.Mvc.Core/Filters/ResultFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Filters/ResultFilterAttribute.cs index dc73c5fc54..1b96715a5c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Filters/ResultFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Filters/ResultFilterAttribute.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -12,18 +11,28 @@ namespace Microsoft.AspNet.Mvc.Filters { public int Order { get; set; } - public virtual void OnResultExecuting([NotNull] ResultExecutingContext context) + public virtual void OnResultExecuting(ResultExecutingContext context) { } - public virtual void OnResultExecuted([NotNull] ResultExecutedContext context) + public virtual void OnResultExecuted(ResultExecutedContext context) { } public virtual async Task OnResultExecutionAsync( - [NotNull] ResultExecutingContext context, - [NotNull] ResultExecutionDelegate next) + ResultExecutingContext context, + ResultExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + OnResultExecuting(context); if (!context.Cancel) { diff --git a/src/Microsoft.AspNet.Mvc.Core/FormatFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/FormatFilterAttribute.cs index 68785033a9..605f356a94 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FormatFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FormatFilterAttribute.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Formatters; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc /// /// The . /// An instance of . - public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) + public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + return serviceProvider.GetRequiredService(); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatFilter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatFilter.cs index a885ed2232..b123690f13 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatFilter.cs @@ -1,12 +1,12 @@ // 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. +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; using Microsoft.Net.Http.Headers; @@ -58,8 +58,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// 2. If there is a conflicting producesFilter. /// /// The . - public void OnResourceExecuting([NotNull] ResourceExecutingContext context) + public void OnResourceExecuting(ResourceExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (!IsActive) { return; // no format specified by user, so the filter is muted @@ -92,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Formatters } /// - public void OnResourceExecuted([NotNull] ResourceExecutedContext context) + public void OnResourceExecuted(ResourceExecutedContext context) { } @@ -100,8 +105,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// Sets a Content Type on an using a format value from the request. /// /// The . - public void OnResultExecuting([NotNull] ResultExecutingContext context) + public void OnResultExecuting(ResultExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (!IsActive) { return; // no format specified by user, so the filter is muted @@ -116,8 +126,12 @@ namespace Microsoft.AspNet.Mvc.Formatters } /// - public void OnResultExecuted([NotNull] ResultExecutedContext context) + public void OnResultExecuted(ResultExecutedContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } private string GetFormat(ActionContext context) diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatterMappings.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatterMappings.cs index 79b688fc65..d72814bd51 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatterMappings.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/FormatterMappings.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc.Formatters @@ -23,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Formatters /// /// The format value. /// The for the format value. - public void SetMediaTypeMappingForFormat([NotNull] string format, [NotNull] MediaTypeHeaderValue contentType) + public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue contentType) { + if (format == null) + { + throw new ArgumentNullException(nameof(format)); + } + + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + ValidateContentType(contentType); format = RemovePeriodIfPresent(format); _map[format] = contentType.CopyAsReadOnly(); @@ -35,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// /// The format value. /// The for input format. - public MediaTypeHeaderValue GetMediaTypeMappingForFormat([NotNull] string format) + public MediaTypeHeaderValue GetMediaTypeMappingForFormat(string format) { + if (format == null) + { + throw new ArgumentNullException(nameof(format)); + } + format = RemovePeriodIfPresent(format); MediaTypeHeaderValue value = null; @@ -50,8 +64,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// /// The format value. /// true if the format is successfully found and cleared; otherwise, false. - public bool ClearMediaTypeMappingForFormat([NotNull] string format) + public bool ClearMediaTypeMappingForFormat(string format) { + if (format == null) + { + throw new ArgumentNullException(nameof(format)); + } + format = RemovePeriodIfPresent(format); return _map.Remove(format); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs index 980b297976..9de2716eb2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc.Formatters @@ -102,8 +101,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// The formatter context associated with the call. /// /// The to use when reading the request or writing the response. - public virtual Encoding SelectCharacterEncoding([NotNull] OutputFormatterContext context) + public virtual Encoding SelectCharacterEncoding(OutputFormatterContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var request = context.HttpContext.Request; var encoding = MatchAcceptCharacterEncoding(request.GetTypedHeaders().AcceptCharset); if (encoding == null) @@ -125,8 +129,13 @@ namespace Microsoft.AspNet.Mvc.Formatters } /// - public virtual bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType) + public virtual bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var runtimeType = context.Object == null ? null : context.Object.GetType(); if (!CanWriteType(context.DeclaredType, runtimeType)) { @@ -158,8 +167,13 @@ namespace Microsoft.AspNet.Mvc.Formatters } /// - public Task WriteAsync([NotNull] OutputFormatterContext context) + public Task WriteAsync(OutputFormatterContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + WriteResponseHeaders(context); return WriteResponseBodyAsync(context); } @@ -168,8 +182,13 @@ namespace Microsoft.AspNet.Mvc.Formatters /// Sets the headers on object. /// /// The formatter context associated with the call. - public virtual void WriteResponseHeaders([NotNull] OutputFormatterContext context) + public virtual void WriteResponseHeaders(OutputFormatterContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var selectedMediaType = context.SelectedContentType; // If content type is not set then set it based on supported media types. @@ -211,7 +230,7 @@ namespace Microsoft.AspNet.Mvc.Formatters /// /// The formatter context associated with the call. /// A task which can write the response body. - public abstract Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context); + public abstract Task WriteResponseBodyAsync(OutputFormatterContext context); private Encoding MatchAcceptCharacterEncoding(IList acceptCharsetHeaders) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/StreamOutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/StreamOutputFormatter.cs index 7e5b52a8b2..471e6d403d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/StreamOutputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/StreamOutputFormatter.cs @@ -1,10 +1,10 @@ // 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. +using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc.Formatters @@ -15,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Formatters public class StreamOutputFormatter : IOutputFormatter { /// - public bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType) + public bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Ignore the passed in content type, if the object is a Stream. if (context.Object is Stream) { @@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Mvc.Formatters } /// - public async Task WriteAsync([NotNull] OutputFormatterContext context) + public async Task WriteAsync(OutputFormatterContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + using (var valueAsStream = ((Stream)context.Object)) { var response = context.HttpContext.Response; diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/StringOutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/StringOutputFormatter.cs index ee819fb64e..27a22e77f3 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/StringOutputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/StringOutputFormatter.cs @@ -1,6 +1,7 @@ // 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. +using System; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; @@ -23,6 +24,11 @@ namespace Microsoft.AspNet.Mvc.Formatters public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Ignore the passed in content type, if the object is string // always return it as a text/plain format. if (context.DeclaredType == typeof(string)) @@ -40,6 +46,11 @@ namespace Microsoft.AspNet.Mvc.Formatters public override Task WriteResponseBodyAsync(OutputFormatterContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var valueAsString = (string)context.Object; if (string.IsNullOrEmpty(valueAsString)) { diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpDeleteAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpDeleteAttribute.cs index 9e057f114c..77323e17f1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpDeleteAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpDeleteAttribute.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpDeleteAttribute([NotNull] string template) + public HttpDeleteAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpGetAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpGetAttribute.cs index f5eef5d654..0405fc1dc5 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpGetAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpGetAttribute.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpGetAttribute([NotNull] string template) + public HttpGetAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpHeadAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpHeadAttribute.cs index 0dedeec95d..e5c3ffc2cb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpHeadAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpHeadAttribute.cs @@ -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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpHeadAttribute([NotNull] string template) + public HttpHeadAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpPatchAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpPatchAttribute.cs index ea8fcab8b6..0cb9930c88 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpPatchAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpPatchAttribute.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpPatchAttribute([NotNull] string template) + public HttpPatchAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpPostAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpPostAttribute.cs index bfc8f20827..93931cd4dd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpPostAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpPostAttribute.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpPostAttribute([NotNull] string template) + public HttpPostAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpPutAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/HttpPutAttribute.cs index a70ed6c8b7..f4291021d1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpPutAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpPutAttribute.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public HttpPutAttribute([NotNull] string template) + public HttpPutAttribute(string template) : base(_supportedMethods, template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpResponseStreamWriter.cs b/src/Microsoft.AspNet.Mvc.Core/HttpResponseStreamWriter.cs index c195bbb289..d9b49c9c62 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpResponseStreamWriter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpResponseStreamWriter.cs @@ -1,11 +1,10 @@ -// 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. using System; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -31,8 +30,18 @@ namespace Microsoft.AspNet.Mvc { } - public HttpResponseStreamWriter([NotNull] Stream stream, [NotNull] Encoding encoding, int bufferSize) + public HttpResponseStreamWriter(Stream stream, Encoding encoding, int bufferSize) { + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + + if (encoding == null) + { + throw new ArgumentNullException(nameof(encoding)); + } + _stream = stream; Encoding = encoding; _encoder = encoding.GetEncoder(); diff --git a/src/Microsoft.AspNet.Mvc.Core/HttpStatusCodeResult.cs b/src/Microsoft.AspNet.Mvc.Core/HttpStatusCodeResult.cs index 5aedaa4035..6e663a261f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/HttpStatusCodeResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/HttpStatusCodeResult.cs @@ -1,7 +1,7 @@ // 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. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Mvc { @@ -27,8 +27,13 @@ namespace Microsoft.AspNet.Mvc public int StatusCode { get; private set; } /// - public override void ExecuteResult([NotNull] ActionContext context) + public override void ExecuteResult(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + context.HttpContext.Response.StatusCode = StatusCode; } } diff --git a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs index 08fd338913..a85f2404b2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc /// /// The context object for the generated URLs for an action method. /// The fully qualified or absolute URL to an action method. - string Action([NotNull] UrlActionContext actionContext); + string Action(UrlActionContext actionContext); /// /// Converts a virtual (relative) path to an application absolute path. @@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc /// /// The context object for the generated URLs for a route. /// The fully qualified or absolute URL. - string RouteUrl([NotNull] UrlRouteContext routeContext); + string RouteUrl(UrlRouteContext routeContext); /// /// Generates an absolute URL using the specified route name and values. diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/ActionDescriptorsCollection.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/ActionDescriptorsCollection.cs index 63082125f6..d7fc85bfe8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/ActionDescriptorsCollection.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/ActionDescriptorsCollection.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Infrastructure { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure /// /// The result of action discovery /// The unique version of discovered actions. - public ActionDescriptorsCollection([NotNull] IReadOnlyList items, int version) + public ActionDescriptorsCollection(IReadOnlyList items, int version) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + Items = items; Version = version; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultActionSelector.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultActionSelector.cs index 7b5560aeb9..ad30cea86e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultActionSelector.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultActionSelector.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Infrastructure @@ -35,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure _logger = loggerFactory.CreateLogger(); } - public Task SelectAsync([NotNull] RouteContext context) + public Task SelectAsync(RouteContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var tree = _decisionTreeProvider.DecisionTree; var matchingRouteConstraints = tree.Select(context.RouteData.Values); @@ -169,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure _logger.LogVerbose( "Action '{ActionDisplayName}' with id '{ActionId}' did not match the " + - "constraint '{ActionConstraint}'", + "constraint '{ActionConstraint}'", candidate.Action.DisplayName, candidate.Action.Id, constraint); @@ -216,8 +220,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure // any link - this gives WebFX a chance to 'veto' the values provided by a route. // // This method does not take httpmethod or dynamic action constraints into account. - public virtual bool HasValidAction([NotNull] VirtualPathContext context) + public virtual bool HasValidAction(VirtualPathContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + if (context.ProvidedValues == null) { // We need the route's values to be able to double check our work. diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultTypeActivatorCache.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultTypeActivatorCache.cs index 32c98af73d..d0aa9466fe 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultTypeActivatorCache.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/DefaultTypeActivatorCache.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Concurrent; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Infrastructure { @@ -21,9 +20,19 @@ namespace Microsoft.AspNet.Mvc.Infrastructure /// public TInstance CreateInstance( - [NotNull] IServiceProvider serviceProvider, - [NotNull] Type implementationType) + IServiceProvider serviceProvider, + Type implementationType) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + + if (implementationType == null) + { + throw new ArgumentNullException(nameof(implementationType)); + } + var createFactory = _typeActivatorCache.GetOrAdd(implementationType, _createFactory); return (TInstance)createFactory(serviceProvider, arguments: null); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs index f809a0084d..72eda561a0 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Infrastructure @@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure private ILogger _logger; private TelemetrySource _telemetry; - public VirtualPathData GetVirtualPath([NotNull] VirtualPathContext context) + public VirtualPathData GetVirtualPath(VirtualPathContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + EnsureServices(context.Context); // The contract of this method is to check that the values coming in from the route are valid; @@ -35,8 +39,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure return null; } - public async Task RouteAsync([NotNull] RouteContext context) + public async Task RouteAsync(RouteContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var services = context.HttpContext.RequestServices; // Verify if AddMvc was done before calling UseMvc @@ -75,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure { _telemetry.WriteTelemetry( "Microsoft.AspNet.Mvc.BeforeAction", - new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData}); + new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData }); } using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id)) @@ -106,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure { var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor); _actionContextAccessor.ActionContext = actionContext; - + var invoker = _actionInvokerFactory.CreateInvoker(actionContext); if (invoker == null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/RouteConstraintAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/RouteConstraintAttribute.cs index 0484438ad6..0f31c57d24 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/RouteConstraintAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/RouteConstraintAttribute.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Infrastructure { @@ -30,9 +29,14 @@ namespace Microsoft.AspNet.Mvc.Infrastructure /// or . /// protected RouteConstraintAttribute( - [NotNull] string routeKey, + string routeKey, RouteKeyHandling keyHandling) { + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + RouteKey = routeKey; RouteKeyHandling = keyHandling; @@ -56,10 +60,20 @@ namespace Microsoft.AspNet.Mvc.Infrastructure /// Set to true to negate this constraint on all actions that do not define a behavior for this route key. /// protected RouteConstraintAttribute( - [NotNull]string routeKey, - [NotNull]string routeValue, + string routeKey, + string routeValue, bool blockNonAttributedActions) { + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (routeValue == null) + { + throw new ArgumentNullException(nameof(routeValue)); + } + RouteKey = routeKey; RouteValue = routeValue; BlockNonAttributedActions = blockNonAttributedActions; diff --git a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcBuilder.cs index 742f58bd99..66da18bc21 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcBuilder.cs @@ -1,15 +1,20 @@ // 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. +using System; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Internal { public class MvcBuilder : IMvcBuilder { - public MvcBuilder([NotNull] IServiceCollection services) + public MvcBuilder(IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + Services = services; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcCoreBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcCoreBuilder.cs index 43ee424535..10d212a1b6 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Internal/MvcCoreBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Internal/MvcCoreBuilder.cs @@ -1,15 +1,20 @@ // 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. +using System; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Internal { public class MvcCoreBuilder : IMvcCoreBuilder { - public MvcCoreBuilder([NotNull] IServiceCollection services) + public MvcCoreBuilder(IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + Services = services; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Internal/NonDisposableStream.cs b/src/Microsoft.AspNet.Mvc.Core/Internal/NonDisposableStream.cs index f06d60584a..3204131755 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Internal/NonDisposableStream.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Internal/NonDisposableStream.cs @@ -1,13 +1,10 @@ // 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. -#if DNX451 using System; -#endif using System.IO; using System.Threading; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Internal { @@ -24,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Internal /// Initializes a new . /// /// The stream which should not be closed or flushed. - public NonDisposableStream([NotNull] Stream innerStream) + public NonDisposableStream(Stream innerStream) { + if (innerStream == null) + { + throw new ArgumentNullException(nameof(innerStream)); + } + _innerStream = innerStream; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs index 61b5e69fdc..06debcf8d3 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class ArrayModelBinder : CollectionModelBinder { /// - public override Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public override Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + if (bindingContext.ModelMetadata.IsReadOnly) { return ModelBindingResult.NoResultAsync; @@ -51,8 +55,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - protected override void CopyToModel([NotNull] object target, IEnumerable sourceCollection) + protected override void CopyToModel(object target, IEnumerable sourceCollection) { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } // Do not attempt to copy values into an array because an array's length is immutable. This choice is also // consistent with MutableObjectModelBinder's handling of a read-only array property. } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceValueProvider.cs index 6099e321ab..ce50c9bef1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceValueProvider.cs @@ -2,9 +2,7 @@ // 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 Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -33,8 +31,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The . Must be a single-source (non-composite) with /// equal to false. /// - public BindingSourceValueProvider([NotNull] BindingSource bindingSource) + public BindingSourceValueProvider(BindingSource bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + if (bindingSource.IsGreedy) { var message = Resources.FormatBindingSource_CannotBeGreedy( @@ -68,6 +71,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// public virtual IValueProvider Filter(BindingSource bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + if (bindingSource.CanAcceptDataFrom(BindingSource)) { return this; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs index 3cf40ec7f1..b62726ddd8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Formatters; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -42,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// A which when completed returns a . /// - private async Task BindModelCoreAsync([NotNull] ModelBindingContext bindingContext) + private async Task BindModelCoreAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + // For compatibility with MVC 5.0 for top level object we want to consider an empty key instead of // the parameter name/a custom name. In all other cases (like when binding body to a property) we // consider the entire ModelName as a prefix. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs index a32c2a1835..fd5d86adca 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -13,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class ByteArrayModelBinder : IModelBinder { /// - public Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + // This method is optimized to use cached tasks when possible and avoid allocating // using Task.FromResult. If you need to make changes of this nature, profile // allocations afterwards and look for Task. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs index d797b80fab..af351d3323 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs @@ -12,7 +12,6 @@ using System.Reflection; #endif using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class CollectionModelBinder : ICollectionModelBinder { /// - public virtual async Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public virtual async Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + ModelBindingHelper.ValidateBindingContext(bindingContext); var model = bindingContext.Model; @@ -303,8 +307,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// Collection of values retrieved from value providers. Or null if nothing was bound. /// - protected virtual void CopyToModel([NotNull] object target, IEnumerable sourceCollection) + protected virtual void CopyToModel(object target, IEnumerable sourceCollection) { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + var targetCollection = target as ICollection; Debug.Assert(targetCollection != null, "This binder is instantiated only for ICollection model types."); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs index cfa6d338e0..7efc8abfa9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs @@ -5,9 +5,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -25,16 +23,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Initializes a new instance of the CompositeModelBinder class. /// /// A collection of instances. - public CompositeModelBinder([NotNull] IEnumerable modelBinders) + public CompositeModelBinder(IEnumerable modelBinders) { + if (modelBinders == null) + { + throw new ArgumentNullException(nameof(modelBinders)); + } + ModelBinders = new List(modelBinders); } /// public IReadOnlyList ModelBinders { get; } - public virtual Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public virtual Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + var newBindingContext = CreateNewBindingContext(bindingContext); if (newBindingContext == null) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeValueProvider.cs index 7ffa938daa..d005cd9549 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeValueProvider.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -47,9 +46,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// created. /// public static async Task CreateAsync( - [NotNull] IEnumerable factories, - [NotNull] ValueProviderFactoryContext context) + IEnumerable factories, + ValueProviderFactoryContext context) { + if (factories == null) + { + throw new ArgumentNullException(nameof(factories)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var composite = new CompositeValueProvider(); foreach (var valueProvidersFactory in factories) { @@ -114,20 +123,35 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - protected override void InsertItem(int index, [NotNull] IValueProvider item) + protected override void InsertItem(int index, IValueProvider item) { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + base.InsertItem(index, item); } /// - protected override void SetItem(int index, [NotNull] IValueProvider item) + protected override void SetItem(int index, IValueProvider item) { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + base.SetItem(index, item); } /// public IValueProvider Filter(BindingSource bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + var filteredValueProviders = new List(); foreach (var valueProvider in this.OfType()) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryBasedValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryBasedValueProvider.cs index 7069f692d9..ace0d4cf33 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryBasedValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryBasedValueProvider.cs @@ -1,10 +1,9 @@ // 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. +using System; using System.Collections.Generic; using System.Globalization; -using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -12,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// An adapter for data stored in an /// . /// - public class DictionaryBasedValueProvider: BindingSourceValueProvider + public class DictionaryBasedValueProvider : BindingSourceValueProvider { private readonly IDictionary _values; private PrefixContainer _prefixContainer; @@ -23,10 +22,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The of the data. /// The values. public DictionaryBasedValueProvider( - [NotNull] BindingSource bindingSource, - [NotNull] IDictionary values) + BindingSource bindingSource, + IDictionary values) : base(bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + _values = values; } @@ -50,8 +59,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public override ValueProviderResult GetValue([NotNull] string key) + public override ValueProviderResult GetValue(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + object value; if (_values.TryGetValue(key, out value)) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs index 68898d0ee4..b7beb0c78d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs @@ -10,7 +10,6 @@ using System.Reflection; #endif using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class DictionaryModelBinder : CollectionModelBinder> { /// - public override async Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public override async Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + var result = await base.BindModelAsync(bindingContext); if (!result.IsModelSet) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs index 5be3a27dfc..5fb48e82ca 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs @@ -1,6 +1,7 @@ // 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. +using System; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ModelBinding.Metadata; @@ -22,6 +23,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public void GetBindingMetadata(BindingMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Don't bother with ModelBindingMessageProvider copy constructor. No other provider can change the // delegates. context.BindingMetadata.ModelBindingMessageProvider = _messageProvider; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs index 0c11c55000..e27acdcc08 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.ModelBinding @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class FormCollectionModelBinder : IModelBinder { /// - public Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + // This method is optimized to use cached tasks when possible and avoid allocating // using Task.FromResult. If you need to make changes of this nature, profile // allocations afterwards and look for Task. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs index bbe3a46eb2..d7ddfdc985 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs @@ -11,7 +11,6 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc.ModelBinding @@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class FormFileModelBinder : IModelBinder { /// - public Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + // This method is optimized to use cached tasks when possible and avoid allocating // using Task.FromResult. If you need to make changes of this nature, profile // allocations afterwards and look for Task. @@ -38,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } private async Task BindModelCoreAsync(ModelBindingContext bindingContext) - { + { object value; if (bindingContext.ModelType == typeof(IFormFile)) { @@ -56,13 +60,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding Debug.Fail("We shouldn't be called without a matching type."); return ModelBindingResult.NoResult; } - + if (value == null) { return ModelBindingResult.Failed(bindingContext.ModelName); } else - { + { bindingContext.ValidationState.Add(value, new ValidationStateEntry() { SuppressValidation = true }); bindingContext.ModelState.SetModelValue( bindingContext.ModelName, diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormValueProviderFactory.cs index cd2f1bbf07..ddd638857b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormValueProviderFactory.cs @@ -1,17 +1,22 @@ // 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. +using System; using System.Globalization; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { public class FormValueProviderFactory : IValueProviderFactory { - public async Task GetValueProviderAsync([NotNull] ValueProviderFactoryContext context) + public async Task GetValueProviderAsync(ValueProviderFactoryContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var request = context.HttpContext.Request; if (request.HasFormContentType) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/IBindingSourceValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/IBindingSourceValueProvider.cs index 752f0fc2e7..49d3f715ac 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/IBindingSourceValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/IBindingSourceValueProvider.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ModelBinding { /// @@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The filtered value provider, or null if the value provider does not match /// . /// - IValueProvider Filter([NotNull] BindingSource bindingSource); + IValueProvider Filter(BindingSource bindingSource); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProvider.cs index 264011c196..d05fdd629c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProvider.cs @@ -1,11 +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. using System; using System.Collections.Generic; using System.Globalization; -using System.Threading.Tasks; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.ModelBinding @@ -25,11 +23,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// A delegate which provides the values to wrap. /// The culture to return with ValueProviderResult instances. public JQueryFormValueProvider( - [NotNull] BindingSource bindingSource, - [NotNull] IDictionary values, + BindingSource bindingSource, + IDictionary values, CultureInfo culture) : base(bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + _values = values; Culture = culture; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs index c416364a48..bdd7af49e0 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -8,15 +8,19 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.ModelBinding { public class JQueryFormValueProviderFactory : IValueProviderFactory { - public async Task GetValueProviderAsync([NotNull] ValueProviderFactoryContext context) + public async Task GetValueProviderAsync(ValueProviderFactoryContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var request = context.HttpContext.Request; if (request.HasFormContentType) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadataProviderContext.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadataProviderContext.cs index f509dad084..8eff371daf 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadataProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadataProviderContext.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -17,9 +17,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// The for the . /// The attributes for the . public BindingMetadataProviderContext( - [NotNull] ModelMetadataIdentity key, - [NotNull] ModelAttributes attributes) + ModelMetadataIdentity key, + ModelAttributes attributes) { + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + Key = key; Attributes = attributes.Attributes; PropertyAttributes = attributes.PropertyAttributes; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs index d951eb61d4..36f5a328d5 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -27,8 +26,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata } /// - public void GetBindingMetadata([NotNull] BindingMetadataProviderContext context) + public void GetBindingMetadata(BindingMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // BinderModelName foreach (var binderModelNameAttribute in context.Attributes.OfType()) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs index 33542b8160..c8b153b1fd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -24,8 +24,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata } /// - public virtual void GetBindingMetadata([NotNull] BindingMetadataProviderContext context) + public virtual void GetBindingMetadata(BindingMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var provider in _providers.OfType()) { provider.GetBindingMetadata(context); @@ -33,8 +38,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata } /// - public virtual void GetDisplayMetadata([NotNull] DisplayMetadataProviderContext context) + public virtual void GetDisplayMetadata(DisplayMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var provider in _providers.OfType()) { provider.GetDisplayMetadata(context); @@ -42,8 +52,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata } /// - public virtual void GetValidationMetadata([NotNull] ValidationMetadataProviderContext context) + public virtual void GetValidationMetadata(ValidationMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var provider in _providers.OfType()) { provider.GetValidationMetadata(context); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultMetadataDetails.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultMetadataDetails.cs index 350b4be3fd..36fad1c9c7 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultMetadataDetails.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultMetadataDetails.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// /// The . /// The set of model attributes. - public DefaultMetadataDetails(ModelMetadataIdentity key, [NotNull] ModelAttributes attributes) + public DefaultMetadataDetails(ModelMetadataIdentity key, ModelAttributes attributes) { + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + Key = key; ModelAttributes = attributes; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs index 62a80040a9..9d85f561a9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs @@ -39,11 +39,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// The . /// The . public DefaultModelMetadata( - [NotNull] IModelMetadataProvider provider, - [NotNull] ICompositeMetadataDetailsProvider detailsProvider, - [NotNull] DefaultMetadataDetails details) + IModelMetadataProvider provider, + ICompositeMetadataDetailsProvider detailsProvider, + DefaultMetadataDetails details) : base(details.Key) { + if (provider == null) + { + throw new ArgumentNullException(nameof(provider)); + } + + if (detailsProvider == null) + { + throw new ArgumentNullException(nameof(detailsProvider)); + } + + if (details == null) + { + throw new ArgumentNullException(nameof(details)); + } + _provider = provider; _detailsProvider = detailsProvider; _details = details; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs index 334d3bc10d..312f2a89e0 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs @@ -34,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata protected ICompositeMetadataDetailsProvider DetailsProvider { get; } /// - public virtual IEnumerable GetMetadataForProperties([NotNull]Type modelType) + public virtual IEnumerable GetMetadataForProperties(Type modelType) { + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + var key = ModelMetadataIdentity.ForType(modelType); var cacheEntry = _typeCache.GetOrAdd(key, _cacheEntryFactory); @@ -59,8 +64,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata } /// - public virtual ModelMetadata GetMetadataForType([NotNull] Type modelType) + public virtual ModelMetadata GetMetadataForType(Type modelType) { + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + var key = ModelMetadataIdentity.ForType(modelType); var cacheEntry = _typeCache.GetOrAdd(key, _cacheEntryFactory); @@ -102,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// . Override this method to provide a different /// set of property data. /// - protected virtual DefaultMetadataDetails[] CreatePropertyDetails([NotNull] ModelMetadataIdentity key) + protected virtual DefaultMetadataDetails[] CreatePropertyDetails(ModelMetadataIdentity key) { var propertyHelpers = PropertyHelper.GetVisibleProperties(key.ModelType); @@ -151,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// . Override this method to provide a different /// set of attributes. /// - protected virtual DefaultMetadataDetails CreateTypeDetails([NotNull] ModelMetadataIdentity key) + protected virtual DefaultMetadataDetails CreateTypeDetails(ModelMetadataIdentity key) { return new DefaultMetadataDetails(key, ModelAttributes.GetAttributesForType(key.ModelType)); } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs index 17c324586f..d158a5ccb8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs @@ -1,8 +1,8 @@ // 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. +using System; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -12,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata public class DefaultValidationMetadataProvider : IValidationMetadataProvider { /// - public void GetValidationMetadata([NotNull] ValidationMetadataProviderContext context) + public void GetValidationMetadata(ValidationMetadataProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + foreach (var attribute in context.Attributes) { if (attribute is IModelValidator || attribute is IClientModelValidator) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DisplayMetadataProviderContext.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DisplayMetadataProviderContext.cs index f51c743994..680a239e3d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DisplayMetadataProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DisplayMetadataProviderContext.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -17,9 +17,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// The for the . /// The attributes for the . public DisplayMetadataProviderContext( - [NotNull] ModelMetadataIdentity key, - [NotNull] ModelAttributes attributes) + ModelMetadataIdentity key, + ModelAttributes attributes) { + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + Key = key; Attributes = attributes.Attributes; PropertyAttributes = attributes.PropertyAttributes; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IBindingMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IBindingMetadataProvider.cs index c7c35a7af7..da2574adb9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IBindingMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IBindingMetadataProvider.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { /// @@ -14,6 +12,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// Gets the values for properties of . /// /// The . - void GetBindingMetadata([NotNull] BindingMetadataProviderContext context); + void GetBindingMetadata(BindingMetadataProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IDisplayMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IDisplayMetadataProvider.cs index 69416aae44..5b57f63109 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IDisplayMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IDisplayMetadataProvider.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { /// @@ -14,6 +12,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// Gets the values for properties of . /// /// The . - void GetDisplayMetadata([NotNull] DisplayMetadataProviderContext context); + void GetDisplayMetadata(DisplayMetadataProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IValidationMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IValidationMetadataProvider.cs index 1da255b18e..da2af3af54 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IValidationMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/IValidationMetadataProvider.cs @@ -1,8 +1,6 @@ // 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. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { /// @@ -14,6 +12,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// Gets the values for properties of . /// /// The . - void GetValidationMetadata([NotNull] ValidationMetadataProviderContext context); + void GetValidationMetadata(ValidationMetadataProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs index a6a7c3d5b1..047ea84549 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ModelAttributes.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Creates a new for a . /// /// The set of attributes for the . - public ModelAttributes([NotNull] IEnumerable typeAttributes) + public ModelAttributes(IEnumerable typeAttributes) { + if (typeAttributes == null) + { + throw new ArgumentNullException(nameof(typeAttributes)); + } + Attributes = typeAttributes.ToArray(); TypeAttributes = Attributes; } @@ -31,8 +35,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The set of attributes for the property's . See . /// - public ModelAttributes([NotNull] IEnumerable propertyAttributes, [NotNull] IEnumerable typeAttributes) + public ModelAttributes(IEnumerable propertyAttributes, IEnumerable typeAttributes) { + if (propertyAttributes == null) + { + throw new ArgumentNullException(nameof(propertyAttributes)); + } + + if (typeAttributes == null) + { + throw new ArgumentNullException(nameof(typeAttributes)); + } + PropertyAttributes = propertyAttributes.ToArray(); TypeAttributes = typeAttributes.ToArray(); Attributes = PropertyAttributes.Concat(TypeAttributes).ToArray(); @@ -65,8 +79,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// A for which attributes need to be resolved. /// /// A instance with the attributes of the property. - public static ModelAttributes GetAttributesForProperty([NotNull] Type type, [NotNull] PropertyInfo property) + public static ModelAttributes GetAttributesForProperty(Type type, PropertyInfo property) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + + if (property == null) + { + throw new ArgumentNullException(nameof(property)); + } + var propertyAttributes = property.GetCustomAttributes(); var typeAttributes = property.PropertyType.GetTypeInfo().GetCustomAttributes(); @@ -89,8 +113,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The for which attributes need to be resolved. /// /// A instance with the attributes of the . - public static ModelAttributes GetAttributesForType([NotNull] Type type) + public static ModelAttributes GetAttributesForType(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + var attributes = type.GetTypeInfo().GetCustomAttributes(); var metadataType = GetMetadataType(type); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ValidationMetadataProviderContext.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ValidationMetadataProviderContext.cs index 6b93c86d4b..a5ef6c4efb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ValidationMetadataProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/ValidationMetadataProviderContext.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -17,9 +17,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// The for the . /// The attributes for the . public ValidationMetadataProviderContext( - [NotNull] ModelMetadataIdentity key, - [NotNull] ModelAttributes attributes) + ModelMetadataIdentity key, + ModelAttributes attributes) { + if (attributes == null) + { + throw new ArgumentNullException(nameof(attributes)); + } + Key = key; Attributes = attributes.Attributes; PropertyAttributes = attributes.PropertyAttributes; diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ModelBindingHelper.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ModelBindingHelper.cs index 9134c68af1..45ded30869 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ModelBindingHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ModelBindingHelper.cs @@ -15,7 +15,6 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -45,18 +44,68 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// on the model instance. /// A that on completion returns true if the update is successful public static Task TryUpdateModelAsync( - [NotNull] TModel model, - [NotNull] string prefix, - [NotNull] HttpContext httpContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IModelBinder modelBinder, - [NotNull] IValueProvider valueProvider, - [NotNull] IList inputFormatters, - [NotNull] IObjectModelValidator objectModelValidator, - [NotNull] IModelValidatorProvider validatorProvider) + TModel model, + string prefix, + HttpContext httpContext, + ModelStateDictionary modelState, + IModelMetadataProvider metadataProvider, + IModelBinder modelBinder, + IValueProvider valueProvider, + IList inputFormatters, + IObjectModelValidator objectModelValidator, + IModelValidatorProvider validatorProvider) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (modelBinder == null) + { + throw new ArgumentNullException(nameof(modelBinder)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (objectModelValidator == null) + { + throw new ArgumentNullException(nameof(objectModelValidator)); + } + + if (validatorProvider == null) + { + throw new ArgumentNullException(nameof(validatorProvider)); + } + // Includes everything by default. return TryUpdateModelAsync( model, @@ -99,19 +148,74 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// which need to be included for the current model. /// A that on completion returns true if the update is successful public static Task TryUpdateModelAsync( - [NotNull] TModel model, - [NotNull] string prefix, - [NotNull] HttpContext httpContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IModelBinder modelBinder, - [NotNull] IValueProvider valueProvider, - [NotNull] IList inputFormatters, - [NotNull] IObjectModelValidator objectModelValidator, - [NotNull] IModelValidatorProvider validatorProvider, - [NotNull] params Expression>[] includeExpressions) + TModel model, + string prefix, + HttpContext httpContext, + ModelStateDictionary modelState, + IModelMetadataProvider metadataProvider, + IModelBinder modelBinder, + IValueProvider valueProvider, + IList inputFormatters, + IObjectModelValidator objectModelValidator, + IModelValidatorProvider validatorProvider, + params Expression>[] includeExpressions) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (modelBinder == null) + { + throw new ArgumentNullException(nameof(modelBinder)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (objectModelValidator == null) + { + throw new ArgumentNullException(nameof(objectModelValidator)); + } + + if (validatorProvider == null) + { + throw new ArgumentNullException(nameof(validatorProvider)); + } + + if (includeExpressions == null) + { + throw new ArgumentNullException(nameof(includeExpressions)); + } + var includeExpression = GetIncludePredicateExpression(prefix, includeExpressions); var predicate = includeExpression.Compile(); @@ -155,19 +259,74 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// filter properties(for inclusion/exclusion) at runtime. /// A that on completion returns true if the update is successful public static Task TryUpdateModelAsync( - [NotNull] TModel model, - [NotNull] string prefix, - [NotNull] HttpContext httpContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IModelBinder modelBinder, - [NotNull] IValueProvider valueProvider, - [NotNull] IList inputFormatters, - [NotNull] IObjectModelValidator objectModelValidator, - [NotNull] IModelValidatorProvider validatorProvider, - [NotNull] Func predicate) + TModel model, + string prefix, + HttpContext httpContext, + ModelStateDictionary modelState, + IModelMetadataProvider metadataProvider, + IModelBinder modelBinder, + IValueProvider valueProvider, + IList inputFormatters, + IObjectModelValidator objectModelValidator, + IModelValidatorProvider validatorProvider, + Func predicate) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (modelBinder == null) + { + throw new ArgumentNullException(nameof(modelBinder)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (objectModelValidator == null) + { + throw new ArgumentNullException(nameof(objectModelValidator)); + } + + if (validatorProvider == null) + { + throw new ArgumentNullException(nameof(validatorProvider)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + return TryUpdateModelAsync( model, typeof(TModel), @@ -207,18 +366,73 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// on the model instance. /// A that on completion returns true if the update is successful public static Task TryUpdateModelAsync( - [NotNull] object model, - [NotNull] Type modelType, - [NotNull] string prefix, - [NotNull] HttpContext httpContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IModelBinder modelBinder, - [NotNull] IValueProvider valueProvider, - [NotNull] IList inputFormatters, - [NotNull] IObjectModelValidator objectModelValidator, - [NotNull] IModelValidatorProvider validatorProvider) + object model, + Type modelType, + string prefix, + HttpContext httpContext, + ModelStateDictionary modelState, + IModelMetadataProvider metadataProvider, + IModelBinder modelBinder, + IValueProvider valueProvider, + IList inputFormatters, + IObjectModelValidator objectModelValidator, + IModelValidatorProvider validatorProvider) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (modelBinder == null) + { + throw new ArgumentNullException(nameof(modelBinder)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (objectModelValidator == null) + { + throw new ArgumentNullException(nameof(objectModelValidator)); + } + + if (validatorProvider == null) + { + throw new ArgumentNullException(nameof(validatorProvider)); + } + // Includes everything by default. return TryUpdateModelAsync( model, @@ -261,19 +475,79 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// filter properties(for inclusion/exclusion) at runtime. /// A that on completion returns true if the update is successful public static async Task TryUpdateModelAsync( - [NotNull] object model, - [NotNull] Type modelType, - [NotNull] string prefix, - [NotNull] HttpContext httpContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IModelBinder modelBinder, - [NotNull] IValueProvider valueProvider, - [NotNull] IList inputFormatters, - [NotNull] IObjectModelValidator objectModelValidator, - [NotNull] IModelValidatorProvider validatorProvider, - [NotNull] Func predicate) + object model, + Type modelType, + string prefix, + HttpContext httpContext, + ModelStateDictionary modelState, + IModelMetadataProvider metadataProvider, + IModelBinder modelBinder, + IValueProvider valueProvider, + IList inputFormatters, + IObjectModelValidator objectModelValidator, + IModelValidatorProvider validatorProvider, + Func predicate) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (modelBinder == null) + { + throw new ArgumentNullException(nameof(modelBinder)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (inputFormatters == null) + { + throw new ArgumentNullException(nameof(inputFormatters)); + } + + if (objectModelValidator == null) + { + throw new ArgumentNullException(nameof(objectModelValidator)); + } + + if (validatorProvider == null) + { + throw new ArgumentNullException(nameof(validatorProvider)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + if (!modelType.IsAssignableFrom(model.GetType())) { var message = Resources.FormatModelType_WrongType( @@ -310,7 +584,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (modelBindingResult.IsModelSet) { objectModelValidator.Validate( - operationBindingContext.ValidatorProvider, + operationBindingContext.ValidatorProvider, modelState, modelBindingContext.ValidationState, modelBindingResult.Key, @@ -408,11 +682,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The entry to clear. /// The . public static void ClearValidationStateForModel( - [NotNull] Type modelType, - [NotNull] ModelStateDictionary modelstate, - [NotNull] IModelMetadataProvider metadataProvider, + Type modelType, + ModelStateDictionary modelstate, + IModelMetadataProvider metadataProvider, string modelKey) { + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + + if (modelstate == null) + { + throw new ArgumentNullException(nameof(modelstate)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + // If modelkey is empty, we need to iterate through properties (obtained from ModelMetadata) and // clear validation state for all entries in ModelStateDictionary that start with each property name. // If modelkey is non-empty, clear validation state for all entries in ModelStateDictionary @@ -438,8 +727,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - internal static void ValidateBindingContext([NotNull] ModelBindingContext bindingContext) + internal static void ValidateBindingContext(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + if (bindingContext.ModelMetadata == null) { throw new ArgumentException(Resources.ModelBinderUtil_ModelMetadataCannotBeNull, nameof(bindingContext)); @@ -560,8 +854,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The converted value or null if the value could not be converted. /// - public static object ConvertTo(object value, [NotNull] Type type) + public static object ConvertTo(object value, Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + return ConvertTo(value, type, culture: null); } @@ -574,8 +873,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The converted value or null if the value could not be converted. /// - public static object ConvertTo(object value, [NotNull] Type type, CultureInfo culture) + public static object ConvertTo(object value, Type type, CultureInfo culture) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + if (value == null) { // For value types, treat null values as though they were the default value for the type. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs index 0057880cbc..e94fa618fb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding typeof(MutableObjectModelBinder).GetTypeInfo().GetDeclaredMethod(nameof(CallPropertyAddRange)); /// - public Task BindModelAsync([NotNull] ModelBindingContext bindingContext) + public Task BindModelAsync(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + ModelBindingHelper.ValidateBindingContext(bindingContext); if (!CanBindType(bindingContext.ModelMetadata)) { @@ -63,8 +67,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// for the property of interest. /// true if the property can be updated; false otherwise. /// Should return true only for properties can update. - protected virtual bool CanUpdateProperty([NotNull] ModelMetadata propertyMetadata) + protected virtual bool CanUpdateProperty(ModelMetadata propertyMetadata) { + if (propertyMetadata == null) + { + throw new ArgumentNullException(nameof(propertyMetadata)); + } + return CanUpdatePropertyInternal(propertyMetadata); } @@ -314,8 +323,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The . /// An compatible with . - protected virtual object CreateModel([NotNull] ModelBindingContext bindingContext) + protected virtual object CreateModel(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + // If the Activator throws an exception, we want to propagate it back up the call stack, since the // application developer should know that this was an invalid type to try to bind to. return Activator.CreateInstance(bindingContext.ModelType); @@ -326,8 +340,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// new instance of . /// /// The . - protected virtual object GetModel([NotNull] ModelBindingContext bindingContext) + protected virtual object GetModel(ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + if (bindingContext.Model != null) { return bindingContext.Model; @@ -342,8 +361,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The . /// Collection of for properties this binder should update. protected virtual IEnumerable GetMetadataForProperties( - [NotNull] ModelBindingContext bindingContext) + ModelBindingContext bindingContext) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + var validationInfo = GetPropertyValidationInfo(bindingContext); var newPropertyFilter = GetPropertyFilter(); return bindingContext.ModelMetadata.Properties @@ -440,11 +464,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The for the property's new value. /// Should succeed in all cases that returns true. protected virtual void SetProperty( - [NotNull] ModelBindingContext bindingContext, - [NotNull] ModelMetadata metadata, - [NotNull] ModelMetadata propertyMetadata, - [NotNull] ModelBindingResult result) + ModelBindingContext bindingContext, + ModelMetadata metadata, + ModelMetadata propertyMetadata, + ModelBindingResult result) { + if (bindingContext == null) + { + throw new ArgumentNullException(nameof(bindingContext)); + } + + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + if (propertyMetadata == null) + { + throw new ArgumentNullException(nameof(propertyMetadata)); + } + var bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase; var property = bindingContext.ModelType.GetProperty(propertyMetadata.PropertyName, bindingFlags); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/PrefixContainer.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/PrefixContainer.cs index 636148cf4e..6e226d1255 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/PrefixContainer.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/PrefixContainer.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -18,15 +17,25 @@ namespace Microsoft.AspNet.Mvc.ModelBinding private readonly ICollection _originalValues; private readonly string[] _sortedValues; - public PrefixContainer([NotNull] ICollection values) + public PrefixContainer(ICollection values) { + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + _originalValues = values; _sortedValues = ToArrayWithoutNulls(_originalValues); Array.Sort(_sortedValues, StringComparer.OrdinalIgnoreCase); } - public bool ContainsPrefix([NotNull] string prefix) + public bool ContainsPrefix(string prefix) { + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + if (prefix.Length == 0) { return _sortedValues.Length > 0; // only match empty string when we have some value diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/QueryStringValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/QueryStringValueProviderFactory.cs index 2096aa0649..2e7969b9e9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/QueryStringValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/QueryStringValueProviderFactory.cs @@ -1,9 +1,9 @@ // 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. +using System; using System.Globalization; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -14,8 +14,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public class QueryStringValueProviderFactory : IValueProviderFactory { /// - public Task GetValueProviderAsync([NotNull] ValueProviderFactoryContext context) + public Task GetValueProviderAsync(ValueProviderFactoryContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return Task.FromResult(new ReadableStringCollectionValueProvider( BindingSource.Query, context.HttpContext.Request.Query, diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ReadableStringCollectionValueProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ReadableStringCollectionValueProvider.cs index 5bb47fa870..fd50bd5be4 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ReadableStringCollectionValueProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ReadableStringCollectionValueProvider.cs @@ -1,10 +1,10 @@ // 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. +using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -24,11 +24,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The key value pairs to wrap. /// The culture to return with ValueProviderResult instances. public ReadableStringCollectionValueProvider( - [NotNull] BindingSource bindingSource, - [NotNull] IReadableStringCollection values, + BindingSource bindingSource, + IReadableStringCollection values, CultureInfo culture) : base(bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + _values = values; _culture = culture; } @@ -61,14 +71,24 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public virtual IDictionary GetKeysFromPrefix([NotNull] string prefix) + public virtual IDictionary GetKeysFromPrefix(string prefix) { + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + return PrefixContainer.GetKeysFromPrefix(prefix); } /// - public override ValueProviderResult GetValue([NotNull] string key) + public override ValueProviderResult GetValue(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + var values = _values[key]; if (values.Count == 0) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/RouteValueValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/RouteValueValueProviderFactory.cs index 6b1d8b9fad..74e01682e4 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/RouteValueValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/RouteValueValueProviderFactory.cs @@ -1,15 +1,20 @@ // 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. +using System; using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { public class RouteValueValueProviderFactory : IValueProviderFactory { - public Task GetValueProviderAsync([NotNull] ValueProviderFactoryContext context) + public Task GetValueProviderAsync(ValueProviderFactoryContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return Task.FromResult(new DictionaryBasedValueProvider( BindingSource.Path, context.RouteValues)); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeClientModelValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeClientModelValidatorProvider.cs index fa1b7effd8..45336f6055 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeClientModelValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeClientModelValidatorProvider.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// /// A collection of instances. /// - public CompositeClientModelValidatorProvider([NotNull] IEnumerable providers) + public CompositeClientModelValidatorProvider(IEnumerable providers) { + if (providers == null) + { + throw new ArgumentNullException(nameof(providers)); + } + ValidatorProviders = new List(providers); } @@ -30,6 +35,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// public void GetValidators(ClientValidatorProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // Perf: Avoid allocations for (var i = 0; i < ValidatorProviders.Count; i++) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeModelValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeModelValidatorProvider.cs index ab4661b452..f43bea00ae 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeModelValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/CompositeModelValidatorProvider.cs @@ -1,8 +1,8 @@ // 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. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// /// A collection of instances. /// - public CompositeModelValidatorProvider([NotNull] IEnumerable providers) + public CompositeModelValidatorProvider(IEnumerable providers) { + if (providers == null) + { + throw new ArgumentNullException(nameof(providers)); + } + ValidatorProviders = new List(providers); } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeBasedExcludeFilter.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeBasedExcludeFilter.cs index e77dffe58d..0ea1d04225 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeBasedExcludeFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeBasedExcludeFilter.cs @@ -3,7 +3,6 @@ using System; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// Creates a new instance of . /// /// The type which needs to be excluded. - public DefaultTypeBasedExcludeFilter([NotNull] Type type) + public DefaultTypeBasedExcludeFilter(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + ExcludedType = type; } @@ -28,8 +32,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation public Type ExcludedType { get; } /// - public bool IsTypeExcluded([NotNull] Type propertyType) + public bool IsTypeExcluded(Type propertyType) { + if (propertyType == null) + { + throw new ArgumentNullException(nameof(propertyType)); + } + return ExcludedType.GetTypeInfo().IsAssignableFrom(propertyType.GetTypeInfo()); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeNameBasedExcludeFilter.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeNameBasedExcludeFilter.cs index a76c39d8de..df933f04a0 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeNameBasedExcludeFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultTypeNameBasedExcludeFilter.cs @@ -3,7 +3,6 @@ using System; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// Creates a new instance of /// /// Fully qualified name of the type which needs to be excluded. - public DefaultTypeNameBasedExcludeFilter([NotNull] string typeFullName) + public DefaultTypeNameBasedExcludeFilter(string typeFullName) { + if (typeFullName == null) + { + throw new ArgumentNullException(nameof(typeFullName)); + } + ExcludedTypeName = typeFullName; } @@ -28,8 +32,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation public string ExcludedTypeName { get; } /// - public bool IsTypeExcluded([NotNull] Type propertyType) + public bool IsTypeExcluded(Type propertyType) { + if (propertyType == null) + { + throw new ArgumentNullException(nameof(propertyType)); + } + return CheckIfTypeNameMatches(propertyType); } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/ExcludeTypeValidationFilterCollection.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/ExcludeTypeValidationFilterCollection.cs index 7444b28da5..1a507f656b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/ExcludeTypeValidationFilterCollection.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/ExcludeTypeValidationFilterCollection.cs @@ -1,9 +1,8 @@ -// 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. using System; using System.Collections.ObjectModel; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// the specified and its derived types from validaton. /// /// which should be excluded from validation. - public void Add([NotNull] Type type) + public void Add(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + var typeBasedExcludeFilter = new DefaultTypeBasedExcludeFilter(type); Add(typeBasedExcludeFilter); } @@ -25,8 +29,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// the specified and its derived types from validaton. /// /// Full name of the type which should be excluded from validation. - public void Add([NotNull] string typeFullName) + public void Add(string typeFullName) { + if (typeFullName == null) + { + throw new ArgumentNullException(nameof(typeFullName)); + } + var filter = new DefaultTypeNameBasedExcludeFilter(typeFullName); Add(filter); } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/IExcludeTypeValidationFilter.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/IExcludeTypeValidationFilter.cs index 2a2cf57a4e..6b013b4311 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/IExcludeTypeValidationFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/IExcludeTypeValidationFilter.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -16,6 +15,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// /// The for which the check is to be performed. /// True if the type is to be excluded. False otherwise. - bool IsTypeExcluded([NotNull] Type type); + bool IsTypeExcluded(Type type); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/SimpleTypesExcludeFilter.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/SimpleTypesExcludeFilter.cs index 072f1120da..bb68f6d065 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/SimpleTypesExcludeFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/SimpleTypesExcludeFilter.cs @@ -17,6 +17,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// public bool IsTypeExcluded(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + Type[] actualTypes; if (type.GetTypeInfo().IsGenericType && diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ValueProviderResultExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ValueProviderResultExtensions.cs index a5dc10f3fc..aa2173ca8f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ValueProviderResultExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ValueProviderResultExtensions.cs @@ -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. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -41,8 +40,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The converted value, or the default value of if the value could not be converted. /// - public static object ConvertTo(this ValueProviderResult result, [NotNull] Type type) + public static object ConvertTo(this ValueProviderResult result, Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + object valueToConvert = null; if (result.Values.Count == 1) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelMetadataTypeAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/ModelMetadataTypeAttribute.cs index 01222589d2..deab607307 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelMetadataTypeAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelMetadataTypeAttribute.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc /// Initializes a new instance of the class. /// /// The type of metadata class that is associated with a data model class. - public ModelMetadataTypeAttribute([NotNull] Type type) + public ModelMetadataTypeAttribute(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + MetadataType = type; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs b/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs index 154e99e8b4..6118036689 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ObjectResult.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Internal; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; using Microsoft.Net.Http.Headers; @@ -43,7 +42,7 @@ namespace Microsoft.AspNet.Mvc public override Task ExecuteResultAsync(ActionContext context) { var logger = context.HttpContext.RequestServices.GetRequiredService>(); - + // See if the list of content types added to this object result is valid. ThrowIfUnsupportedContentType(); var formatters = GetDefaultFormatters(context); @@ -68,7 +67,7 @@ namespace Microsoft.AspNet.Mvc logger.LogVerbose( "Selected output formatter '{OutputFormatter}' and content type " + - "'{ContentType}' to write the response.", + "'{ContentType}' to write the response.", selectedFormatter.GetType().FullName, formatterContext.SelectedContentType); @@ -92,7 +91,7 @@ namespace Microsoft.AspNet.Mvc if (ContentTypes.Count == 1) { logger.LogVerbose( - "Skipped content negotiation as content type '{ContentType}' is explicitly set for the response.", + "Skipped content negotiation as content type '{ContentType}' is explicitly set for the response.", ContentTypes[0]); return SelectFormatterUsingAnyAcceptableContentType(formatterContext, @@ -159,8 +158,8 @@ namespace Microsoft.AspNet.Mvc { // Filter and remove accept headers which cannot support any of the user specified content types. var filteredAndSortedAcceptHeaders = sortedAcceptHeaderMediaTypes - .Where(acceptHeader => - ContentTypes.Any(contentType => + .Where(acceptHeader => + ContentTypes.Any(contentType => contentType.IsSubsetOf(acceptHeader))); selectedFormatter = SelectFormatterUsingSortedAcceptHeaders( @@ -330,8 +329,12 @@ namespace Microsoft.AspNet.Mvc /// /// This method is called before the formatter writes to the output stream. /// - protected virtual void OnFormatting([NotNull] ActionContext context) + protected virtual void OnFormatting(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/PhysicalFileProviderResult.cs b/src/Microsoft.AspNet.Mvc.Core/PhysicalFileProviderResult.cs index 0f739898e3..979e8d9f64 100644 --- a/src/Microsoft.AspNet.Mvc.Core/PhysicalFileProviderResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/PhysicalFileProviderResult.cs @@ -1,13 +1,13 @@ -// 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. +using System; using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Mvc.Core; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -27,9 +27,17 @@ namespace Microsoft.AspNet.Mvc /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - public PhysicalFileProviderResult([NotNull] string fileName, [NotNull] string contentType) + public PhysicalFileProviderResult(string fileName, string contentType) : this(fileName, new MediaTypeHeaderValue(contentType)) { + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } } /// @@ -38,9 +46,19 @@ namespace Microsoft.AspNet.Mvc /// /// The path to the file. The path must be an absolute path. /// The Content-Type header of the response. - public PhysicalFileProviderResult([NotNull] string fileName, [NotNull] MediaTypeHeaderValue contentType) + public PhysicalFileProviderResult(string fileName, MediaTypeHeaderValue contentType) : base(contentType) { + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + FileName = fileName; } @@ -53,10 +71,13 @@ namespace Microsoft.AspNet.Mvc { return _fileName; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _fileName = value; } } @@ -98,8 +119,13 @@ namespace Microsoft.AspNet.Mvc /// /// The path for which the is needed. /// for the specified . - protected virtual Stream GetFileStream([NotNull]string path) + protected virtual Stream GetFileStream(string path) { + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } + return new FileStream( path, FileMode.Open, diff --git a/src/Microsoft.AspNet.Mvc.Core/ProducesAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/ProducesAttribute.cs index 846b1ab24d..1f06e711c4 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ProducesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ProducesAttribute.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Formatters; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -24,8 +23,13 @@ namespace Microsoft.AspNet.Mvc /// Initializes an instance of . /// /// The of object that is going to be written in the response. - public ProducesAttribute([NotNull] Type type) + public ProducesAttribute(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + Type = type; ContentTypes = new List(); } @@ -35,8 +39,13 @@ namespace Microsoft.AspNet.Mvc /// /// The allowed content type for a response. /// Additional allowed content types for a response. - public ProducesAttribute([NotNull] string contentType, params string[] additionalContentTypes) + public ProducesAttribute(string contentType, params string[] additionalContentTypes) { + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + ContentTypes = GetContentTypes(contentType, additionalContentTypes); } @@ -44,8 +53,13 @@ namespace Microsoft.AspNet.Mvc public IList ContentTypes { get; set; } - public override void OnResultExecuting([NotNull] ResultExecutingContext context) + public override void OnResultExecuting(ResultExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + base.OnResultExecuting(context); var objectResult = context.Result as ObjectResult; diff --git a/src/Microsoft.AspNet.Mvc.Core/RedirectResult.cs b/src/Microsoft.AspNet.Mvc.Core/RedirectResult.cs index 9a15223ab5..86d71b914e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RedirectResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RedirectResult.cs @@ -3,10 +3,8 @@ using System; using Microsoft.AspNet.Mvc.Core; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -14,13 +12,22 @@ namespace Microsoft.AspNet.Mvc { private string _url; - public RedirectResult([NotNull] string url) + public RedirectResult(string url) : this(url, permanent: false) { + if (url == null) + { + throw new ArgumentNullException(nameof(url)); + } } - public RedirectResult([NotNull] string url, bool permanent) + public RedirectResult(string url, bool permanent) { + if (url == null) + { + throw new ArgumentNullException(nameof(url)); + } + if (string.IsNullOrEmpty(url)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); @@ -51,8 +58,13 @@ namespace Microsoft.AspNet.Mvc public IUrlHelper UrlHelper { get; set; } - public override void ExecuteResult([NotNull] ActionContext context) + public override void ExecuteResult(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var urlHelper = GetUrlHelper(context); // IsLocalUrl is called to handle Urls starting with '~/'. diff --git a/src/Microsoft.AspNet.Mvc.Core/RedirectToActionResult.cs b/src/Microsoft.AspNet.Mvc.Core/RedirectToActionResult.cs index 3a2d5fbcec..7b4a996f3d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RedirectToActionResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RedirectToActionResult.cs @@ -4,10 +4,8 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Core; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -43,8 +41,13 @@ namespace Microsoft.AspNet.Mvc public bool Permanent { get; set; } - public override void ExecuteResult([NotNull] ActionContext context) + public override void ExecuteResult(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var urlHelper = GetUrlHelper(context); var destinationUrl = urlHelper.Action(ActionName, ControllerName, RouteValues); diff --git a/src/Microsoft.AspNet.Mvc.Core/RedirectToRouteResult.cs b/src/Microsoft.AspNet.Mvc.Core/RedirectToRouteResult.cs index 4c4ebb3ea1..3a9b0aa3c7 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RedirectToRouteResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RedirectToRouteResult.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Core; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; @@ -43,8 +42,13 @@ namespace Microsoft.AspNet.Mvc public bool Permanent { get; set; } - public override void ExecuteResult([NotNull] ActionContext context) + public override void ExecuteResult(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var urlHelper = GetUrlHelper(context); var destinationUrl = urlHelper.RouteUrl(RouteName, RouteValues); diff --git a/src/Microsoft.AspNet.Mvc.Core/RequireHttpsAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/RequireHttpsAttribute.cs index 307123f140..84d06d200c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RequireHttpsAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RequireHttpsAttribute.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -13,8 +12,13 @@ namespace Microsoft.AspNet.Mvc { public int Order { get; set; } - public virtual void OnAuthorization([NotNull]AuthorizationContext filterContext) + public virtual void OnAuthorization(AuthorizationContext filterContext) { + if (filterContext == null) + { + throw new ArgumentNullException(nameof(filterContext)); + } + if (!filterContext.HttpContext.Request.IsHttps) { HandleNonHttpsRequest(filterContext); diff --git a/src/Microsoft.AspNet.Mvc.Core/ResponseCacheAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/ResponseCacheAttribute.cs index a16013f08f..e8598b1565 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ResponseCacheAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ResponseCacheAttribute.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Filters; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc @@ -87,8 +86,13 @@ namespace Microsoft.AspNet.Mvc /// public int Order { get; set; } - public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) + public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + var optionsAccessor = serviceProvider.GetRequiredService>(); CacheProfile selectedProfile = null; @@ -110,7 +114,7 @@ namespace Microsoft.AspNet.Mvc _noStore = _noStore ?? selectedProfile?.NoStore; _location = _location ?? selectedProfile?.Location; VaryByHeader = VaryByHeader ?? selectedProfile?.VaryByHeader; - + // ResponseCacheFilter cannot take any null values. Hence, if there are any null values, // the properties convert them to their defaults and are passed on. return new ResponseCacheFilter( diff --git a/src/Microsoft.AspNet.Mvc.Core/RouteAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/RouteAttribute.cs index 02005a40c2..06ac635f35 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RouteAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RouteAttribute.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc /// Creates a new with the given route template. /// /// The route template. May not be null. - public RouteAttribute([NotNull] string template) + public RouteAttribute(string template) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } + Template = template; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRoute.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRoute.cs index 06117f4368..58ec223fcb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRoute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRoute.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing.Template; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Routing @@ -28,11 +27,31 @@ namespace Microsoft.AspNet.Mvc.Routing private InnerAttributeRoute _inner; public AttributeRoute( - [NotNull] IRouter target, - [NotNull] IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider, - [NotNull] IInlineConstraintResolver constraintResolver, - [NotNull] ILoggerFactory loggerFactory) + IRouter target, + IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider, + IInlineConstraintResolver constraintResolver, + ILoggerFactory loggerFactory) { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (actionDescriptorsCollectionProvider == null) + { + throw new ArgumentNullException(nameof(actionDescriptorsCollectionProvider)); + } + + if (constraintResolver == null) + { + throw new ArgumentNullException(nameof(constraintResolver)); + } + + if (loggerFactory == null) + { + throw new ArgumentNullException(nameof(loggerFactory)); + } + _target = target; _actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider; _constraintResolver = constraintResolver; diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRouting.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRouting.cs index ac69431722..deb2dc7c88 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRouting.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/AttributeRouting.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Routing @@ -22,8 +21,18 @@ namespace Microsoft.AspNet.Mvc.Routing /// The router to invoke when a route entry matches. /// The application services. /// An attribute route. - public static IRouter CreateAttributeMegaRoute([NotNull] IRouter target, [NotNull] IServiceProvider services) + public static IRouter CreateAttributeMegaRoute(IRouter target, IServiceProvider services) { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + var actionDescriptorProvider = services.GetRequiredService(); var inlineConstraintResolver = services.GetRequiredService(); var loggerFactory = services.GetRequiredService(); diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/HttpMethodAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/HttpMethodAttribute.cs index 5113239e92..c5ea198c39 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/HttpMethodAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/HttpMethodAttribute.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Routing { @@ -22,9 +21,13 @@ namespace Microsoft.AspNet.Mvc.Routing /// set of HTTP methods. /// The set of supported HTTP methods. /// - public HttpMethodAttribute([NotNull] IEnumerable httpMethods) + public HttpMethodAttribute(IEnumerable httpMethods) : this(httpMethods, null) { + if (httpMethods == null) + { + throw new ArgumentNullException(nameof(httpMethods)); + } } /// @@ -33,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Routing /// /// The set of supported methods. /// The route template. May not be null. - public HttpMethodAttribute([NotNull] IEnumerable httpMethods, string template) + public HttpMethodAttribute(IEnumerable httpMethods, string template) { + if (httpMethods == null) + { + throw new ArgumentNullException(nameof(httpMethods)); + } + _httpMethods = httpMethods; Template = template; } diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs index b431a7912a..aacfa00ef1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs @@ -9,7 +9,6 @@ using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Internal.Routing; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing.Template; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Mvc.Routing @@ -33,13 +32,38 @@ namespace Microsoft.AspNet.Mvc.Routing /// The next router. Invoked when a route entry matches. /// The set of route entries. public InnerAttributeRoute( - [NotNull] IRouter next, - [NotNull] IEnumerable matchingEntries, - [NotNull] IEnumerable linkGenerationEntries, - [NotNull] ILogger logger, - [NotNull] ILogger constraintLogger, + IRouter next, + IEnumerable matchingEntries, + IEnumerable linkGenerationEntries, + ILogger logger, + ILogger constraintLogger, int version) { + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + + if (matchingEntries == null) + { + throw new ArgumentNullException(nameof(matchingEntries)); + } + + if (linkGenerationEntries == null) + { + throw new ArgumentNullException(nameof(linkGenerationEntries)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + if (constraintLogger == null) + { + throw new ArgumentNullException(nameof(constraintLogger)); + } + _next = next; _logger = logger; _constraintLogger = constraintLogger; @@ -98,9 +122,14 @@ namespace Microsoft.AspNet.Mvc.Routing public int Version { get; } /// - public async Task RouteAsync([NotNull] RouteContext context) + public async Task RouteAsync(RouteContext context) { - foreach(var matchingEntry in _matchingEntries) + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + foreach (var matchingEntry in _matchingEntries) { var requestPath = context.HttpContext.Request.Path.Value; @@ -161,8 +190,13 @@ namespace Microsoft.AspNet.Mvc.Routing } /// - public VirtualPathData GetVirtualPath([NotNull] VirtualPathContext context) + public VirtualPathData GetVirtualPath(VirtualPathContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // If it's a named route we will try to generate a link directly and // if we can't, we will not try to generate it using an unnamed route. if (context.RouteName != null) diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/KnownRouteValueConstraint.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/KnownRouteValueConstraint.cs index 58a914704f..5b9b7024c8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/KnownRouteValueConstraint.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/KnownRouteValueConstraint.cs @@ -5,12 +5,10 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Routing { @@ -19,12 +17,32 @@ namespace Microsoft.AspNet.Mvc.Routing private RouteValuesCollection _cachedValuesCollection; public bool Match( - [NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value)) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs index 4dca31b5c5..c6affd13be 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; using Microsoft.Framework.Internal; @@ -47,12 +46,17 @@ namespace Microsoft.AspNet.Mvc.Routing /// public virtual string Action(UrlActionContext actionContext) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + var valuesDictionary = PropertyHelper.ObjectToDictionary(actionContext.Values); if (actionContext.Action == null) { object action; - if (!valuesDictionary.ContainsKey("action") && + if (!valuesDictionary.ContainsKey("action") && AmbientValues.TryGetValue("action", out action)) { valuesDictionary["action"] = action; @@ -66,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.Routing if (actionContext.Controller == null) { object controller; - if (!valuesDictionary.ContainsKey("controller") && + if (!valuesDictionary.ContainsKey("controller") && AmbientValues.TryGetValue("controller", out controller)) { valuesDictionary["controller"] = controller; @@ -102,6 +106,11 @@ namespace Microsoft.AspNet.Mvc.Routing /// public virtual string RouteUrl(UrlRouteContext routeContext) { + if (routeContext == null) + { + throw new ArgumentNullException(nameof(routeContext)); + } + var valuesDictionary = PropertyHelper.ObjectToDictionary(routeContext.Values); var path = GeneratePathFromRoute(routeContext.RouteName, valuesDictionary); diff --git a/src/Microsoft.AspNet.Mvc.Core/SerializableError.cs b/src/Microsoft.AspNet.Mvc.Core/SerializableError.cs index 78f52f3049..064c7a2183 100644 --- a/src/Microsoft.AspNet.Mvc.Core/SerializableError.cs +++ b/src/Microsoft.AspNet.Mvc.Core/SerializableError.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -28,14 +27,19 @@ namespace Microsoft.AspNet.Mvc /// Creates a new instance of . /// /// containing the validation errors. - public SerializableError([NotNull] ModelStateDictionary modelState) + public SerializableError(ModelStateDictionary modelState) : this() { + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + if (modelState.IsValid) { return; } - + foreach (var keyModelStatePair in modelState) { var key = keyModelStatePair.Key; diff --git a/src/Microsoft.AspNet.Mvc.Core/ServiceFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/ServiceFilterAttribute.cs index f312a35ed9..6221aaf3bb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ServiceFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ServiceFilterAttribute.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Filters; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Mvc [DebuggerDisplay("ServiceFilter: Type={ServiceType} Order={Order}")] public class ServiceFilterAttribute : Attribute, IFilterFactory, IOrderedFilter { - public ServiceFilterAttribute([NotNull] Type type) + public ServiceFilterAttribute(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + ServiceType = type; } @@ -23,8 +27,13 @@ namespace Microsoft.AspNet.Mvc public int Order { get; set; } - public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) + public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + var service = serviceProvider.GetRequiredService(ServiceType); var filter = service as IFilterMetadata; diff --git a/src/Microsoft.AspNet.Mvc.Core/TypeFilterAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/TypeFilterAttribute.cs index 8a4fb6f8e7..dc8f6d92a2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/TypeFilterAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/TypeFilterAttribute.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Linq; using Microsoft.AspNet.Mvc.Filters; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc { private ObjectFactory _factory; - public TypeFilterAttribute([NotNull] Type type) + public TypeFilterAttribute(Type type) { + if (type == null) + { + throw new ArgumentNullException(nameof(type)); + } + ImplementationType = type; } @@ -27,8 +31,13 @@ namespace Microsoft.AspNet.Mvc public int Order { get; set; } - public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) + public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + if (_factory == null) { var argumentTypes = Arguments?.Select(a => a.GetType())?.ToArray(); diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs index 7507cc6307..410a98c050 100644 --- a/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs @@ -1,8 +1,8 @@ // 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. +using System; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -12,8 +12,13 @@ namespace Microsoft.AspNet.Mvc /// Generates a fully qualified or absolute URL for an action method. /// /// The fully qualified or absolute URL to an action method. - public static string Action([NotNull] this IUrlHelper helper) + public static string Action(this IUrlHelper helper) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action( action: null, controller: null, @@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Mvc /// /// The name of the action method. /// The fully qualified or absolute URL to an action method. - public static string Action([NotNull] this IUrlHelper helper, string action) + public static string Action(this IUrlHelper helper, string action) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller: null, values: null, protocol: null, host: null, fragment: null); } @@ -40,8 +50,13 @@ namespace Microsoft.AspNet.Mvc /// The name of the action method. /// An object that contains route values. /// The fully qualified or absolute URL to an action method. - public static string Action([NotNull] this IUrlHelper helper, string action, object values) + public static string Action(this IUrlHelper helper, string action, object values) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller: null, values: values, protocol: null, host: null, fragment: null); } @@ -52,8 +67,13 @@ namespace Microsoft.AspNet.Mvc /// The name of the action method. /// The name of the controller. /// The fully qualified or absolute URL to an action method. - public static string Action([NotNull] this IUrlHelper helper, string action, string controller) + public static string Action(this IUrlHelper helper, string action, string controller) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller, values: null, protocol: null, host: null, fragment: null); } @@ -65,8 +85,13 @@ namespace Microsoft.AspNet.Mvc /// The name of the controller. /// An object that contains route values. /// The fully qualified or absolute URL to an action method. - public static string Action([NotNull] this IUrlHelper helper, string action, string controller, object values) + public static string Action(this IUrlHelper helper, string action, string controller, object values) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller, values, protocol: null, host: null, fragment: null); } @@ -80,12 +105,17 @@ namespace Microsoft.AspNet.Mvc /// The protocol for the URL, such as "http" or "https". /// The fully qualified or absolute URL to an action method. public static string Action( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string action, string controller, object values, string protocol) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller, values, protocol, host: null, fragment: null); } @@ -100,13 +130,18 @@ namespace Microsoft.AspNet.Mvc /// The host name for the URL. /// The fully qualified or absolute URL to an action method. public static string Action( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string action, string controller, object values, string protocol, string host) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(action, controller, values, protocol, host, fragment: null); } @@ -122,7 +157,7 @@ namespace Microsoft.AspNet.Mvc /// The fragment for the URL. /// The fully qualified or absolute URL to an action method. public static string Action( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string action, string controller, object values, @@ -130,6 +165,11 @@ namespace Microsoft.AspNet.Mvc string host, string fragment) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Action(new UrlActionContext() { Action = action, @@ -146,8 +186,13 @@ namespace Microsoft.AspNet.Mvc /// /// An object that contains route values. /// The fully qualified or absolute URL. - public static string RouteUrl([NotNull] this IUrlHelper helper, object values) + public static string RouteUrl(this IUrlHelper helper, object values) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(routeName: null, values: values, protocol: null, host: null, fragment: null); } @@ -156,8 +201,13 @@ namespace Microsoft.AspNet.Mvc /// /// The name of the route that is used to generate URL. /// The fully qualified or absolute URL. - public static string RouteUrl([NotNull] this IUrlHelper helper, string routeName) + public static string RouteUrl(this IUrlHelper helper, string routeName) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(routeName, values: null, protocol: null, host: null, fragment: null); } @@ -168,8 +218,13 @@ namespace Microsoft.AspNet.Mvc /// The name of the route that is used to generate URL. /// An object that contains route values. /// The fully qualified or absolute URL. - public static string RouteUrl([NotNull] this IUrlHelper helper, string routeName, object values) + public static string RouteUrl(this IUrlHelper helper, string routeName, object values) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(routeName, values, protocol: null, host: null, fragment: null); } @@ -182,11 +237,16 @@ namespace Microsoft.AspNet.Mvc /// The protocol for the URL, such as "http" or "https". /// The fully qualified or absolute URL. public static string RouteUrl( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string routeName, object values, string protocol) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(routeName, values, protocol, host: null, fragment: null); } @@ -200,12 +260,17 @@ namespace Microsoft.AspNet.Mvc /// The host name for the URL. /// The fully qualified or absolute URL. public static string RouteUrl( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string routeName, object values, string protocol, string host) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(routeName, values, protocol, host, fragment: null); } @@ -220,13 +285,18 @@ namespace Microsoft.AspNet.Mvc /// The fragment for the URL. /// The fully qualified or absolute URL. public static string RouteUrl( - [NotNull] this IUrlHelper helper, + this IUrlHelper helper, string routeName, object values, string protocol, string host, string fragment) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RouteUrl(new UrlRouteContext() { RouteName = routeName, diff --git a/src/Microsoft.AspNet.Mvc.Core/VirtualFileProviderResult.cs b/src/Microsoft.AspNet.Mvc.Core/VirtualFileProviderResult.cs index ffe39b03aa..d1c954f505 100644 --- a/src/Microsoft.AspNet.Mvc.Core/VirtualFileProviderResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/VirtualFileProviderResult.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Mvc.Core; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc @@ -31,9 +30,17 @@ namespace Microsoft.AspNet.Mvc /// /// The path to the file. The path must be relative/virtual. /// The Content-Type header of the response. - public VirtualFileProviderResult([NotNull] string fileName, [NotNull] string contentType) + public VirtualFileProviderResult(string fileName, string contentType) : this(fileName, new MediaTypeHeaderValue(contentType)) { + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } } /// @@ -43,9 +50,19 @@ namespace Microsoft.AspNet.Mvc /// /// The path to the file. The path must be relative/virtual. /// The Content-Type header of the response. - public VirtualFileProviderResult([NotNull] string fileName, [NotNull] MediaTypeHeaderValue contentType) + public VirtualFileProviderResult(string fileName, MediaTypeHeaderValue contentType) : base(contentType) { + if (fileName == null) + { + throw new ArgumentNullException(nameof(fileName)); + } + + if (contentType == null) + { + throw new ArgumentNullException(nameof(contentType)); + } + FileName = fileName; } @@ -58,10 +75,13 @@ namespace Microsoft.AspNet.Mvc { return _fileName; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _fileName = value; } } @@ -118,8 +138,13 @@ namespace Microsoft.AspNet.Mvc /// /// The for which the stream is needed. /// for the specified . - protected virtual Stream GetFileStream([NotNull]IFileInfo fileInfo) + protected virtual Stream GetFileStream(IFileInfo fileInfo) { + if (fileInfo == null) + { + throw new ArgumentNullException(nameof(fileInfo)); + } + return fileInfo.CreateReadStream(); } diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index cc7ac4a9c1..05c4f8db4c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -19,10 +19,6 @@ "type": "build" }, "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { - "version": "1.0.0-*", - "type": "build" - }, "Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" diff --git a/src/Microsoft.AspNet.Mvc.Cors/CorsApplicationModelProvider.cs b/src/Microsoft.AspNet.Mvc.Cors/CorsApplicationModelProvider.cs index 4e1aef1f43..2b2ab5dab5 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/CorsApplicationModelProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Cors/CorsApplicationModelProvider.cs @@ -1,24 +1,53 @@ -// 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. +using System; using System.Linq; using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Mvc.ApplicationModels; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Cors { public class CorsApplicationModelProvider : IApplicationModelProvider { - public int Order { get { return -1000 + 10; } } + public int Order { get { return -1000 + 10; } } - public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context) + public void OnProvidersExecuted(ApplicationModelProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } // Intentionally empty. } - public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context) + public void OnProvidersExecuting(ApplicationModelProviderContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + IEnableCorsAttribute enableCors; IDisableCorsAttribute disableCors; diff --git a/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilter.cs b/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilter.cs index 2350b36c91..2e2dc6fa9c 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilter.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.Cors @@ -48,8 +47,23 @@ namespace Microsoft.AspNet.Mvc.Cors /// - public async Task OnAuthorizationAsync([NotNull] Filters.AuthorizationContext context) + public async Task OnAuthorizationAsync(Filters.AuthorizationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + // If this filter is not closest to the action, it is not applicable. if (!IsClosestToAction(context.Filters)) { @@ -64,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.Cors var result = _corsService.EvaluatePolicy(context.HttpContext, policy); _corsService.ApplyResult(result, context.HttpContext.Response); - var accessControlRequestMethod = + var accessControlRequestMethod = httpContext.Request.Headers[CorsConstants.AccessControlRequestMethod]; if (string.Equals( request.Method, diff --git a/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilterFactory.cs b/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilterFactory.cs index 282beb461f..ac7a4de129 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilterFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Cors/CorsAuthorizationFilterFactory.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Mvc.Filters; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Cors { @@ -33,8 +32,23 @@ namespace Microsoft.AspNet.Mvc.Cors } } - public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) + public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) { + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + + if (serviceProvider == null) + { + throw new ArgumentNullException(nameof(serviceProvider)); + } + var filter = serviceProvider.GetRequiredService(); filter.PolicyName = _policyName; return filter; diff --git a/src/Microsoft.AspNet.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs index 8e8541255c..f398880b8e 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs @@ -1,4 +1,4 @@ -// 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. using System; @@ -6,22 +6,36 @@ using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.Cors; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { public static class MvcCorsMvcCoreBuilderExtensions { - public static IMvcCoreBuilder AddCors([NotNull] this IMvcCoreBuilder builder) + public static IMvcCoreBuilder AddCors(this IMvcCoreBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + AddCorsServices(builder.Services); return builder; } public static IMvcCoreBuilder AddCors( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] Action setupAction) + this IMvcCoreBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + AddCorsServices(builder.Services); if (setupAction != null) @@ -33,9 +47,19 @@ namespace Microsoft.Framework.DependencyInjection } public static IMvcCoreBuilder ConfigureCors( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] Action setupAction) + this IMvcCoreBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure(setupAction); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.Cors/DisableCorsAuthorizationFilter.cs b/src/Microsoft.AspNet.Mvc.Cors/DisableCorsAuthorizationFilter.cs index e21bb5f40e..6f3cfc6603 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/DisableCorsAuthorizationFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Cors/DisableCorsAuthorizationFilter.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.Cors @@ -26,9 +25,24 @@ namespace Microsoft.AspNet.Mvc.Cors } /// - public Task OnAuthorizationAsync([NotNull] AuthorizationContext context) + public Task OnAuthorizationAsync(AuthorizationContext context) { - var accessControlRequestMethod = + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var accessControlRequestMethod = context.HttpContext.Request.Headers[CorsConstants.AccessControlRequestMethod]; if (string.Equals( context.HttpContext.Request.Method, diff --git a/src/Microsoft.AspNet.Mvc.Cors/project.json b/src/Microsoft.AspNet.Mvc.Cors/project.json index 650d547f81..c9a76e9375 100644 --- a/src/Microsoft.AspNet.Mvc.Cors/project.json +++ b/src/Microsoft.AspNet.Mvc.Cors/project.json @@ -10,11 +10,7 @@ }, "dependencies": { "Microsoft.AspNet.Cors.Core": "6.0.0-*", - "Microsoft.AspNet.Mvc.Core": "6.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { - "version": "1.0.0-*", - "type": "build" - } + "Microsoft.AspNet.Mvc.Core": "6.0.0-*" }, "frameworks": { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index dc0510438f..11c24c29fe 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -1153,10 +1153,6 @@ namespace Microsoft.AspNet.Mvc [NonAction] public virtual void OnActionExecuting(ActionExecutingContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } } /// @@ -1166,10 +1162,6 @@ namespace Microsoft.AspNet.Mvc [NonAction] public virtual void OnActionExecuted(ActionExecutedContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } } /// diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs index a6f387df2a..3997665c9f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs @@ -17,10 +17,6 @@ namespace Microsoft.AspNet.Mvc /// public void OnResourceExecuted(ResourceExecutedContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } } /// diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultApplicationModelProviderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultApplicationModelProviderTest.cs index 22f733b913..d8a3b5113f 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultApplicationModelProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultApplicationModelProviderTest.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; using Xunit; @@ -728,10 +727,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels // OrderBy is used because the order of the results may very depending on the platform / client. var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products"); - Assert.Equal(new [] { "GET", "POST" }, action.HttpMethods.OrderBy(key => key, StringComparer.Ordinal)); + Assert.Equal(new[] { "GET", "POST" }, action.HttpMethods.OrderBy(key => key, StringComparer.Ordinal)); action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products"); - Assert.Equal(new [] { "GET", "POST" }, action.HttpMethods.OrderBy(key => key, StringComparer.Ordinal)); + Assert.Equal(new[] { "GET", "POST" }, action.HttpMethods.OrderBy(key => key, StringComparer.Ordinal)); } [Fact] @@ -1173,34 +1172,34 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public class SomeFiltersController : IAsyncActionFilter, IResultFilter { public Task OnActionExecutionAsync( - [NotNull] ActionExecutingContext context, - [NotNull] ActionExecutionDelegate next) + ActionExecutingContext context, + ActionExecutionDelegate next) { return null; } - public void OnResultExecuted([NotNull] ResultExecutedContext context) + public void OnResultExecuted(ResultExecutedContext context) { } - public void OnResultExecuting([NotNull]ResultExecutingContext context) + public void OnResultExecuting(ResultExecutingContext context) { } } private class UnsupportedFiltersController : IExceptionFilter, IAuthorizationFilter, IAsyncResourceFilter { - public void OnAuthorization([NotNull]AuthorizationContext context) + public void OnAuthorization(AuthorizationContext context) { throw new NotImplementedException(); } - public void OnException([NotNull]ExceptionContext context) + public void OnException(ExceptionContext context) { throw new NotImplementedException(); } - public Task OnResourceExecutionAsync([NotNull]ResourceExecutingContext context, [NotNull]ResourceExecutionDelegate next) + public Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ConsumesAttributeTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ConsumesAttributeTests.cs index 65fd81d4aa..ad6fc81fc6 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ConsumesAttributeTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ConsumesAttributeTests.cs @@ -19,11 +19,10 @@ namespace Microsoft.AspNet.Mvc [Theory] [InlineData("application")] [InlineData("")] - [InlineData(null)] public void Constructor_ForInvalidContentType_Throws(string contentType) { // Arrange - var expectedMessage = string.Format("Invalid value '{0}'.", contentType ?? ""); + var expectedMessage = string.Format("Invalid value '{0}'.", contentType); // Act & Assert var exception = Assert.Throws(() => new ConsumesAttribute(contentType)); @@ -67,7 +66,7 @@ namespace Microsoft.AspNet.Mvc () => new ConsumesAttribute(contentTypes[0], contentTypes.Skip(1).ToArray())); Assert.Equal( - string.Format("The argument '{0}' is invalid. "+ + string.Format("The argument '{0}' is invalid. " + "Media types which match all types or match all subtypes are not supported.", invalidContentType), ex.Message); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs index 20cde61c0e..386dbfee01 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Mvc.ModelBinding.Test; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Routing; using Moq; @@ -39,6 +40,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); @@ -78,6 +80,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var argumentBinder = GetArgumentBinder(); @@ -125,6 +128,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var argumentBinder = GetArgumentBinder(); @@ -647,6 +651,7 @@ namespace Microsoft.AspNet.Mvc.Controllers return new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionDescriptorProviderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionDescriptorProviderTests.cs index e245b8dc04..23e45b12de 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionDescriptorProviderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionDescriptorProviderTests.cs @@ -13,7 +13,6 @@ using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Framework.Internal; using Moq; using Xunit; @@ -2043,7 +2042,7 @@ namespace Microsoft.AspNet.Mvc.Controllers _isVisible = isVisible; } - public void Apply([NotNull] ApplicationModel application) + public void Apply(ApplicationModel application) { application.ApiExplorer.IsVisible = _isVisible; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs index fc7009bff6..2a7409061e 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs @@ -18,7 +18,6 @@ using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Testing; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; using Microsoft.Framework.Logging.Testing; using Microsoft.Framework.OptionsModel; @@ -1975,7 +1974,7 @@ namespace Microsoft.AspNet.Mvc.Controllers { actionDescriptor.MethodInfo = typeof(ControllerActionInvokerTest).GetMethod("ActionMethod"); } - + var httpContext = new Mock(MockBehavior.Loose); var httpRequest = new DefaultHttpContext().Request; var httpResponse = new DefaultHttpContext().Response; @@ -2021,17 +2020,27 @@ namespace Microsoft.AspNet.Mvc.Controllers .Setup(fp => fp.OnProvidersExecuting(It.IsAny())) .Callback(context => { - foreach (var filter in filters.Select(f => new FilterItem(null, f))) + foreach (var filterMetadata in filters) { + var filter = new FilterItem( + new FilterDescriptor(filterMetadata, FilterScope.Action), + filterMetadata); context.Results.Add(filter); } }); - filterProvider.Setup(fp => fp.OnProvidersExecuted(It.IsAny())) - .Verifiable(); + filterProvider + .Setup(fp => fp.OnProvidersExecuted(It.IsAny())) + .Verifiable(); - filterProvider.SetupGet(fp => fp.Order) - .Returns(-1000); + var actionArgumentsBinder = new Mock(); + actionArgumentsBinder.Setup( + b => b.BindActionArgumentsAsync(actionContext, It.IsAny(), It.IsAny())) + .Returns(Task.FromResult>(new Dictionary())); + + filterProvider + .SetupGet(fp => fp.Order) + .Returns(-1000); var invoker = new TestControllerActionInvoker( actionContext, @@ -2040,7 +2049,7 @@ namespace Microsoft.AspNet.Mvc.Controllers actionDescriptor, new IInputFormatter[0], new IOutputFormatter[0], - Mock.Of(), + actionArgumentsBinder.Object, new IModelBinder[0], new IModelValidatorProvider[0], new IValueProviderFactory[0], @@ -2249,7 +2258,7 @@ namespace Microsoft.AspNet.Mvc.Controllers _expectedMaxAllowedErrors = maxAllowedErrors; } - public void OnAuthorization([NotNull]AuthorizationContext context) + public void OnAuthorization(AuthorizationContext context) { Assert.NotNull(context.ModelState.MaxAllowedErrors); Assert.Equal(_expectedMaxAllowedErrors, context.ModelState.MaxAllowedErrors); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/DependencyInjection/ApplicationModelConventionExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/DependencyInjection/ApplicationModelConventionExtensionsTest.cs index 7516d5271c..be931bd7e0 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/DependencyInjection/ApplicationModelConventionExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/DependencyInjection/ApplicationModelConventionExtensionsTest.cs @@ -74,7 +74,7 @@ namespace Microsoft.Framework.DependencyInjection private class SimpleActionConvention : IActionModelConvention { - public void Apply([NotNull] ActionModel action) + public void Apply(ActionModel action) { action.Properties.Add("TestProperty", "TestValue"); } @@ -82,7 +82,7 @@ namespace Microsoft.Framework.DependencyInjection private class SimpleControllerConvention : IControllerModelConvention { - public void Apply([NotNull] ControllerModel controller) + public void Apply(ControllerModel controller) { controller.Properties.Add("TestProperty", "TestValue"); } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/AuthorizeFilterTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/AuthorizeFilterTest.cs index 4a9e70ec83..6fdb9818a4 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Filters/AuthorizeFilterTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Filters/AuthorizeFilterTest.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; using Moq; @@ -324,8 +325,7 @@ namespace Microsoft.AspNet.Mvc.Filters var actionContext = new ActionContext( httpContext: httpContext.Object, routeData: new RouteData(), - actionDescriptor: null - ); + actionDescriptor: new ActionDescriptor()); var authorizationContext = new AuthorizationContext( actionContext, diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Formatters/OutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Formatters/OutputFormatterTests.cs index 7d89def02d..f5f58a8712 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Formatters/OutputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Formatters/OutputFormatterTests.cs @@ -7,7 +7,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; -using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; using Moq; using Xunit; @@ -338,7 +337,7 @@ namespace Microsoft.AspNet.Mvc.Formatters SupportedEncodings.Add(Encoding.UTF8); } - public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) + public override Task WriteResponseBodyAsync(OutputFormatterContext context) { return Task.FromResult(true); } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs index ffc3451764..5eb8bc1d4a 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs @@ -813,7 +813,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure public int Order { get; set; } - public bool Accept([NotNull]ActionConstraintContext context) + public bool Accept(ActionConstraintContext context) { return Pass; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs index 61ccc99619..767a7e473c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs @@ -1,10 +1,8 @@ // 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. -#if DNX451 using System; using System.Threading.Tasks; -using Microsoft.AspNet.Testing; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding.Test @@ -112,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test public async Task BindModel_ReturnsNull_ForOtherTypes() { // Arrange - var bindingContext = GetBindingContext(null, typeof(int[])); + var bindingContext = GetBindingContext(new SimpleValueProvider(), typeof(int[])); var binder = new ByteArrayModelBinder(); // Act @@ -140,4 +138,3 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test } } } -#endif diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs index 9604a9e64c..4ca5b754ca 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs @@ -212,14 +212,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { // Arrange var binder = new CollectionModelBinder(); - - var context = new ModelBindingContext() - { - OperationBindingContext = new OperationBindingContext() - { - MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), - }, - }; + var context = GetModelBindingContext(new SimpleValueProvider()); // Act var boundCollection = await binder.BindSimpleCollection(context, new ValueProviderResult(new string[0])); @@ -357,7 +350,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var culture = new CultureInfo("fr-FR"); var bindingContext = GetModelBindingContext(new SimpleValueProvider()); - Mock.Get(bindingContext.OperationBindingContext.ModelBinder) + Mock.Get(bindingContext.OperationBindingContext.ModelBinder) .Setup(o => o.BindModelAsync(It.IsAny())) .Returns((ModelBindingContext mbc) => { @@ -394,6 +387,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test MetadataProvider = metadataProvider }, ValidationState = new ValidationStateDictionary(), + FieldName = "testfieldname", }; return bindingContext; diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs index 311d01c83e..31e3d8e9dd 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs @@ -30,6 +30,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { "someName", "dummyValue" } }, ValidationState = new ValidationStateDictionary(), + FieldName = "someName", }; var mockIntBinder = new Mock(); @@ -72,6 +73,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { "someName", "dummyValue" } }, ValidationState = new ValidationStateDictionary(), + FieldName = "someName", }; var mockIntBinder = new Mock(); @@ -118,6 +120,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { "someName", "dummyValue" } }, ValidationState = new ValidationStateDictionary(), + FieldName = "someName", }; var mockIntBinder = new Mock(); @@ -164,6 +167,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { "someOtherName", "dummyValue" } }, ValidationState = new ValidationStateDictionary(), + FieldName = "someName", }; var mockIntBinder = new Mock(); @@ -211,6 +215,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { { "someOtherName", "dummyValue" } }, + FieldName = "someName", }; var modelBinder = new Mock(); @@ -242,6 +247,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { { "someOtherName", "dummyValue" } }, + FieldName = "someName", }; var modelBinder = new Mock(); @@ -276,6 +282,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { { "someOtherName", "dummyValue" } }, + FieldName = "someName", }; var modelBinder = new Mock(); @@ -311,6 +318,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { { "someOtherName", "dummyValue" } }, + FieldName = "someName", }; var modelBinder = new Mock(); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs index 775341bf65..d86f62ed29 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs @@ -129,6 +129,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test context.OperationBindingContext.ModelBinder = CreateCompositeBinder(); context.OperationBindingContext.ValueProvider = CreateEnumerableValueProvider(keyFormat, dictionary); context.ValueProvider = context.OperationBindingContext.ValueProvider; + context.FieldName = modelName; var metadataProvider = context.OperationBindingContext.MetadataProvider; context.ModelMetadata = metadataProvider.GetMetadataForProperty( @@ -165,6 +166,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test context.OperationBindingContext.ModelBinder = CreateCompositeBinder(); context.OperationBindingContext.ValueProvider = CreateTestValueProvider("prefix[{0}]", dictionary); context.ValueProvider = context.OperationBindingContext.ValueProvider; + context.FieldName = context.ModelName; var metadataProvider = context.OperationBindingContext.MetadataProvider; context.ModelMetadata = metadataProvider.GetMetadataForProperty( @@ -215,6 +217,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test context.OperationBindingContext.ValueProvider = CreateEnumerableValueProvider("prefix[{0}]", stringDictionary); context.ValueProvider = context.OperationBindingContext.ValueProvider; + context.FieldName = context.ModelName; var metadataProvider = context.OperationBindingContext.MetadataProvider; context.ModelMetadata = metadataProvider.GetMetadataForProperty( @@ -255,6 +258,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test context.OperationBindingContext.ModelBinder = CreateCompositeBinder(); context.OperationBindingContext.ValueProvider = CreateEnumerableValueProvider("{0}", stringDictionary); context.ValueProvider = context.OperationBindingContext.ValueProvider; + context.FieldName = context.ModelName; var metadataProvider = context.OperationBindingContext.MetadataProvider; context.ModelMetadata = metadataProvider.GetMetadataForProperty( @@ -300,6 +304,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test context.OperationBindingContext.ModelBinder = CreateCompositeBinder(); context.OperationBindingContext.ValueProvider = CreateEnumerableValueProvider(keyFormat, dictionary); context.ValueProvider = context.OperationBindingContext.ValueProvider; + context.FieldName = context.ModelName; var metadataProvider = context.OperationBindingContext.MetadataProvider; context.ModelMetadata = metadataProvider.GetMetadataForProperty( diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs index 753b6b3cb7..d6b75b2741 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs @@ -203,7 +203,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test HttpContext = new DefaultHttpContext(), MetadataProvider = new TestModelMetadataProvider(), ModelBinder = new SimpleTypeModelBinder(), - } + }, + ModelState = new ModelStateDictionary(), }; return modelBindingContext; @@ -217,7 +218,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var metataProvider = new EmptyModelMetadataProvider(); var bindingContext = new ModelBindingContext { - ModelMetadata = metataProvider.GetMetadataForType(keyValuePairType ?? typeof(KeyValuePair)), + ModelMetadata = metataProvider.GetMetadataForType( + keyValuePairType ?? typeof(KeyValuePair)), ModelName = "someName", ModelState = new ModelStateDictionary(), ValueProvider = valueProvider, diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingContextTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingContextTest.cs index 02cf9fdfcc..db85fd1b0b 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingContextTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingContextTest.cs @@ -19,7 +19,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test ModelMetadata = new TestModelMetadataProvider().GetMetadataForType(typeof(object)), ModelName = "theName", OperationBindingContext = new OperationBindingContext(), - ValueProvider = new SimpleValueProvider() + ValueProvider = new SimpleValueProvider(), + ModelState = new ModelStateDictionary(), }; var metadataProvider = new TestModelMetadataProvider(); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs index e095ffccca..9027f6d32c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act var result = await ModelBindingHelper.TryUpdateModelAsync( model, - null, + string.Empty, Mock.Of(), new ModelStateDictionary(), metadataProvider, @@ -161,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act var result = await ModelBindingHelper.TryUpdateModelAsync( model, - null, + string.Empty, Mock.Of(), new ModelStateDictionary(), metadataProvider, @@ -207,10 +207,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { "ExcludedProperty", "ExcludedPropertyValue" } }; - Func includePredicate = - (context, propertyName) => - string.Equals(propertyName, "IncludedProperty", StringComparison.OrdinalIgnoreCase) || - string.Equals(propertyName, "MyProperty", StringComparison.OrdinalIgnoreCase); + Func includePredicate = (context, propertyName) => + string.Equals(propertyName, "IncludedProperty", StringComparison.OrdinalIgnoreCase) || + string.Equals(propertyName, "MyProperty", StringComparison.OrdinalIgnoreCase); var valueProvider = new TestValueProvider(values); var metadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); @@ -252,7 +251,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act var result = await ModelBindingHelper.TryUpdateModelAsync( model, - null, + string.Empty, Mock.Of(), new ModelStateDictionary(), metadataProvider, @@ -437,12 +436,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { // Arrange Act & Assert var ex = Assert.Throws(() => - ModelBindingHelper.GetPropertyName(expression.Body)); + ModelBindingHelper.GetPropertyName(expression.Body)); - Assert.Equal(string.Format("The passed expression of expression node type '{0}' is invalid."+ - " Only simple member access expressions for model properties are supported.", - expression.Body.NodeType), - ex.Message); + Assert.Equal( + $"The passed expression of expression node type '{expression.Body.NodeType}' is invalid." + + " Only simple member access expressions for model properties are supported.", + ex.Message); } [Fact] @@ -456,12 +455,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act & Assert var ex = Assert.Throws(() => - ModelBindingHelper.GetPropertyName(expression.Body)); + ModelBindingHelper.GetPropertyName(expression.Body)); - Assert.Equal(string.Format("The passed expression of expression node type '{0}' is invalid." + - " Only simple member access expressions for model properties are supported.", - expression.Body.NodeType), - ex.Message); + Assert.Equal( + $"The passed expression of expression node type '{expression.Body.NodeType}' is invalid." + + " Only simple member access expressions for model properties are supported.", + ex.Message); } [Fact] @@ -472,12 +471,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act & Assert var ex = Assert.Throws(() => - ModelBindingHelper.GetPropertyName(expression.Body)); + ModelBindingHelper.GetPropertyName(expression.Body)); - Assert.Equal(string.Format("The passed expression of expression node type '{0}' is invalid." + - " Only simple member access expressions for model properties are supported.", - expression.Body.NodeType), - ex.Message); + Assert.Equal( + $"The passed expression of expression node type '{expression.Body.NodeType}' is invalid." + + " Only simple member access expressions for model properties are supported.", + ex.Message); } [Fact] @@ -488,12 +487,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act & Assert var ex = Assert.Throws(() => - ModelBindingHelper.GetPropertyName(expression.Body)); + ModelBindingHelper.GetPropertyName(expression.Body)); - Assert.Equal(string.Format("The passed expression of expression node type '{0}' is invalid." + - " Only simple member access expressions for model properties are supported.", - expression.Body.NodeType), - ex.Message); + Assert.Equal( + $"The passed expression of expression node type '{expression.Body.NodeType}' is invalid." + + " Only simple member access expressions for model properties are supported.", + ex.Message); } [Theory] @@ -514,7 +513,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await ModelBindingHelper.TryUpdateModelAsync( model, model.GetType(), - prefix: null, + prefix: "", httpContext: Mock.Of(), modelState: new ModelStateDictionary(), metadataProvider: metadataProvider, @@ -610,7 +609,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await ModelBindingHelper.TryUpdateModelAsync( model, modelType: model.GetType(), - prefix: null, + prefix: "", httpContext: Mock.Of(), modelState: new ModelStateDictionary(), metadataProvider: metadataProvider, @@ -685,20 +684,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Act & Assert var exception = await Assert.ThrowsAsync( () => ModelBindingHelper.TryUpdateModelAsync( - model, - typeof(User), - null, - Mock.Of(), - new ModelStateDictionary(), - metadataProvider, - GetCompositeBinder(binder.Object), - Mock.Of(), - new List(), - new DefaultObjectValidator( - new IExcludeTypeValidationFilter[0], - metadataProvider), - Mock.Of(), - includePredicate)); + model, + typeof(User), + "", + Mock.Of(), + new ModelStateDictionary(), + metadataProvider, + GetCompositeBinder(binder.Object), + Mock.Of(), + new List(), + new DefaultObjectValidator( + new IExcludeTypeValidationFilter[0], + metadataProvider), + Mock.Of(), + includePredicate)); var expectedMessage = string.Format("The model's runtime type '{0}' is not assignable to the type '{1}'." + Environment.NewLine + diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs index 0f7085e54c..004f75fac9 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Moq; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding.Test diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs index a110f658f7..b5e10a2648 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs @@ -47,6 +47,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding MetadataProvider = metadataProvider, ValidatorProvider = Mock.Of(), }, + ModelState = new ModelStateDictionary(), }, }; @@ -79,7 +80,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding }, BindingSource = modelMetadata.BindingSource, BinderModelName = modelMetadata.BinderModelName, - } + ModelState = new ModelStateDictionary(), + }, }; var mutableBinder = new MutableObjectModelBinder(); @@ -105,7 +107,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding OperationBindingContext = new OperationBindingContext { ValidatorProvider = Mock.Of(), - } + }, + ModelState = new ModelStateDictionary(), } }; @@ -141,6 +144,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Setting it to empty ensures that model does not get created because of no model name. ModelName = "dummyModelName", + ModelState = new ModelStateDictionary(), }, }; @@ -182,6 +186,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), }, ValueProvider = mockValueProvider.Object, + ModelState = new ModelStateDictionary(), }, PropertyMetadata = modelMetadata.Properties, }; diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleValueProvider.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleValueProvider.cs index 4fc0a4c856..cebd602948 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleValueProvider.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleValueProvider.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.ModelBinding.Test { diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/RequireHttpsAttributeTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/RequireHttpsAttributeTests.cs index 9513b492b5..5a5dce108f 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/RequireHttpsAttributeTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/RequireHttpsAttributeTests.cs @@ -2,16 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Linq; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Routing; using Xunit; namespace Microsoft.AspNet.Mvc { - public class RequireHttpsAttributeTests { [Fact] @@ -152,9 +151,8 @@ namespace Microsoft.AspNet.Mvc private static AuthorizationContext CreateAuthorizationContext(HttpContext ctx) { - var actionContext = new ActionContext(ctx, new RouteData(), actionDescriptor: null); - - return new AuthorizationContext(actionContext, Enumerable.Empty().ToList()); + var actionContext = new ActionContext(ctx, new RouteData(), new ActionDescriptor()); + return new AuthorizationContext(actionContext, new IFilterMetadata[0]); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs index e0173d4b26..d15c6a138b 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Routing; @@ -32,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Routing // Arrange var values = new Dictionary(); var httpContext = GetHttpContext(new ActionDescriptor()); - var route = (new Mock()).Object; + var route = Mock.Of(); // Act var match = _constraint.Match(httpContext, route, keyName, values, direction); @@ -58,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.Routing "testAction"); actionDescriptor.RouteConstraints.Add(new RouteDataActionConstraint("randomKey", "testRandom")); var httpContext = GetHttpContext(actionDescriptor); - var route = (new Mock()).Object; + var route = Mock.Of(); var values = new Dictionary() { { "area", "testArea" }, @@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.Routing "testAction"); actionDescriptor.RouteConstraints.Add(new RouteDataActionConstraint("randomKey", "testRandom")); var httpContext = GetHttpContext(actionDescriptor); - var route = (new Mock()).Object; + var route = Mock.Of(); var values = new Dictionary() { { "area", "invalidTestArea" }, @@ -116,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.Routing controller: null, action: null); var httpContext = GetHttpContext(actionDescriptor); - var route = (new Mock()).Object; + var route = Mock.Of(); var values = new Dictionary() { { "area", 12 }, @@ -135,20 +134,24 @@ namespace Microsoft.AspNet.Mvc.Routing public void ActionDescriptorsCollection_SettingNullValue_Throws(RouteDirection direction) { // Arrange + var actionDescriptorCollectionProvider = Mock.Of(); var httpContext = new Mock(); - httpContext.Setup(o => o.RequestServices - .GetService(typeof(IActionDescriptorsCollectionProvider))) - .Returns(new Mock().Object); + httpContext + .Setup(o => o.RequestServices.GetService(typeof(IActionDescriptorsCollectionProvider))) + .Returns(actionDescriptorCollectionProvider); + // Act & Assert var ex = Assert.Throws( - () => _constraint.Match(httpContext.Object, - null, - "area", - new Dictionary { { "area", "area" } }, - direction)); - Assert.Equal("The 'ActionDescriptors' property of " + - "'Castle.Proxies.IActionDescriptorsCollectionProviderProxy' must not be null.", - ex.Message); + () => _constraint.Match( + httpContext.Object, + Mock.Of(), + "area", + new Dictionary { { "area", "area" } }, + direction)); + var providerName = actionDescriptorCollectionProvider.GetType().FullName; + Assert.Equal( + $"The 'ActionDescriptors' property of '{providerName}' must not be null.", + ex.Message); } private static HttpContext GetHttpContext(ActionDescriptor actionDescriptor) diff --git a/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsModelValidatorTest.cs b/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsModelValidatorTest.cs index 47b32d7fed..8d0f0dfd57 100644 --- a/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsModelValidatorTest.cs +++ b/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsModelValidatorTest.cs @@ -6,7 +6,6 @@ using System.ComponentModel.DataAnnotations; #if DNX451 using System.Linq; #endif -using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Localization; #if DNX451 using Moq; diff --git a/test/Microsoft.AspNet.Mvc.Formatters.Json.Test/JsonOutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.Formatters.Json.Test/JsonOutputFormatterTests.cs index 97a93e3a0e..01fe079c13 100644 --- a/test/Microsoft.AspNet.Mvc.Formatters.Json.Test/JsonOutputFormatterTests.cs +++ b/test/Microsoft.AspNet.Mvc.Formatters.Json.Test/JsonOutputFormatterTests.cs @@ -8,6 +8,8 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; +using Microsoft.AspNet.Mvc.Abstractions; +using Microsoft.AspNet.Routing; using Microsoft.AspNet.Testing; using Microsoft.Net.Http.Headers; using Moq; @@ -114,10 +116,10 @@ namespace Microsoft.AspNet.Mvc.Formatters var before = new JValue(beforeMessage); var memStream = new MemoryStream(); var outputFormatterContext = GetOutputFormatterContext( - beforeMessage, - typeof(string), - "application/json; charset=utf-8", - memStream); + beforeMessage, + typeof(string), + "application/json; charset=utf-8", + memStream); // Act await formatter.WriteResponseBodyAsync(outputFormatterContext); @@ -238,7 +240,7 @@ namespace Microsoft.AspNet.Mvc.Formatters var httpContext = new Mock(); httpContext.SetupGet(c => c.Request).Returns(request.Object); httpContext.SetupGet(c => c.Response).Returns(response.Object); - return new ActionContext(httpContext.Object, routeData: null, actionDescriptor: null); + return new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor()); } private sealed class User