diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionDescriptorExtensions.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionDescriptorExtensions.cs index 9b263d8e8e..124415e318 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionDescriptorExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionDescriptorExtensions.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.Abstractions { @@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Abstractions /// The type of the property. /// The action descriptor. /// The property or the default value of . - public static T GetProperty([NotNull] this ActionDescriptor actionDescriptor) + public static T GetProperty(this ActionDescriptor actionDescriptor) { + if (actionDescriptor == null) + { + throw new ArgumentNullException(nameof(actionDescriptor)); + } + object value; if (actionDescriptor.Properties.TryGetValue(typeof(T), out value)) { @@ -37,8 +42,18 @@ namespace Microsoft.AspNet.Mvc.Abstractions /// The type of the property. /// The action descriptor. /// The value of the property. - public static void SetProperty([NotNull] this ActionDescriptor actionDescriptor, [NotNull] T value) + public static void SetProperty(this ActionDescriptor actionDescriptor, T value) { + if (actionDescriptor == null) + { + throw new ArgumentNullException(nameof(actionDescriptor)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + actionDescriptor.Properties[typeof(T)] = value; } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionInvokerProviderContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionInvokerProviderContext.cs index 1eaffe904b..4a726a00f1 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionInvokerProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/ActionInvokerProviderContext.cs @@ -1,14 +1,19 @@ // 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.Abstractions { public class ActionInvokerProviderContext { - public ActionInvokerProviderContext([NotNull] ActionContext actionContext) + public ActionInvokerProviderContext(ActionContext actionContext) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + ActionContext = actionContext; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionDescriptorProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionDescriptorProvider.cs index 7b581a2607..e18835af97 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionDescriptorProvider.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.Abstractions { public interface IActionDescriptorProvider @@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Abstractions /// int Order { get; } - void OnProvidersExecuting([NotNull] ActionDescriptorProviderContext context); + void OnProvidersExecuting(ActionDescriptorProviderContext context); - void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context); + void OnProvidersExecuted(ActionDescriptorProviderContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionInvokerProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionInvokerProvider.cs index 9b350c3c49..d64e9522c3 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionInvokerProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Abstractions/IActionInvokerProvider.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.Abstractions { public interface IActionInvokerProvider @@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Abstractions /// int Order { get; } - void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context); + void OnProvidersExecuting(ActionInvokerProviderContext context); - void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context); + void OnProvidersExecuted(ActionInvokerProviderContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs index bd90b39788..3a9ed36166 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.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.ActionConstraints { @@ -15,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints /// Creates a new . /// /// The instance. - public ActionConstraintItem([NotNull] IActionConstraintMetadata metadata) + public ActionConstraintItem(IActionConstraintMetadata metadata) { + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + Metadata = metadata; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs index 72a1cd55e2..183218a6f2 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.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 Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ActionConstraints { @@ -19,10 +19,25 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints /// The for which constraints are being created. /// The list of objects. public ActionConstraintProviderContext( - [NotNull] HttpContext context, - [NotNull] ActionDescriptor action, - [NotNull] IList items) + HttpContext context, + ActionDescriptor action, + IList items) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (action == null) + { + throw new ArgumentNullException(nameof(action)); + } + + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + HttpContext = context; Action = action; Results = items; diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionSelectorCandidate.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionSelectorCandidate.cs index ca5ef9a840..a1b2625312 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionSelectorCandidate.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/ActionSelectorCandidate.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.ActionConstraints { @@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints /// /// The list of instances associated with . /// - public ActionSelectorCandidate([NotNull] ActionDescriptor action, IReadOnlyList constraints) + public ActionSelectorCandidate(ActionDescriptor action, IReadOnlyList constraints) { + if (action == null) + { + throw new ArgumentNullException(nameof(action)); + } + Action = action; Constraints = constraints; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/IActionConstraintProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/IActionConstraintProvider.cs index 7460acdf18..d1a45d5dcd 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/IActionConstraintProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ActionConstraints/IActionConstraintProvider.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.ActionConstraints { public interface IActionConstraintProvider @@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints /// int Order { get; } - void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context); + void OnProvidersExecuting(ActionConstraintProviderContext context); - void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context); + void OnProvidersExecuted(ActionConstraintProviderContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ActionContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ActionContext.cs index e13592f05a..24908a4079 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ActionContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ActionContext.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 Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -29,13 +29,17 @@ namespace Microsoft.AspNet.Mvc /// Creates a new . /// /// The to copy. - public ActionContext([NotNull] ActionContext actionContext) + public ActionContext(ActionContext actionContext) : this( - actionContext.HttpContext, - actionContext.RouteData, - actionContext.ActionDescriptor, + actionContext.HttpContext, + actionContext.RouteData, + actionContext.ActionDescriptor, actionContext.ModelState) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } } /// @@ -45,9 +49,9 @@ namespace Microsoft.AspNet.Mvc /// The for the current request. /// The for the selected action. public ActionContext( - [NotNull] HttpContext httpContext, - [NotNull] RouteData routeData, - [NotNull] ActionDescriptor actionDescriptor) + HttpContext httpContext, + RouteData routeData, + ActionDescriptor actionDescriptor) : this(httpContext, routeData, actionDescriptor, new ModelStateDictionary()) { } @@ -60,11 +64,31 @@ namespace Microsoft.AspNet.Mvc /// The for the selected action. /// The . public ActionContext( - [NotNull] HttpContext httpContext, - [NotNull] RouteData routeData, - [NotNull] ActionDescriptor actionDescriptor, - [NotNull] ModelStateDictionary modelState) + HttpContext httpContext, + RouteData routeData, + ActionDescriptor actionDescriptor, + ModelStateDictionary modelState) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (routeData == null) + { + throw new ArgumentNullException(nameof(routeData)); + } + + if (actionDescriptor == null) + { + throw new ArgumentNullException(nameof(actionDescriptor)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + HttpContext = httpContext; RouteData = routeData; ActionDescriptor = actionDescriptor; diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutedContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutedContext.cs index 199fb6a9e0..dc2da6fd00 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutedContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutedContext.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -14,8 +13,8 @@ namespace Microsoft.AspNet.Mvc.Filters private ExceptionDispatchInfo _exceptionDispatchInfo; public ActionExecutedContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters, + ActionContext actionContext, + IList filters, object controller) : base(actionContext, filters) { diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutingContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutingContext.cs index 12d374769b..08ab7dc767 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutingContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ActionExecutingContext.cs @@ -1,20 +1,25 @@ // 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 { public class ActionExecutingContext : FilterContext { public ActionExecutingContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters, - [NotNull] IDictionary actionArguments, + ActionContext actionContext, + IList filters, + IDictionary actionArguments, object controller) : base(actionContext, filters) { + if (actionArguments == null) + { + throw new ArgumentNullException(nameof(actionArguments)); + } + ActionArguments = actionArguments; Controller = controller; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/AuthorizationContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/AuthorizationContext.cs index 64f58d2f74..a5306ce165 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/AuthorizationContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/AuthorizationContext.cs @@ -1,16 +1,16 @@ // 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 { public class AuthorizationContext : FilterContext { public AuthorizationContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters) + ActionContext actionContext, + IList filters) : base(actionContext, filters) { } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ExceptionContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ExceptionContext.cs index 381bcd3c8f..024f21f5d7 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ExceptionContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ExceptionContext.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -13,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.Filters private Exception _exception; private ExceptionDispatchInfo _exceptionDispatchInfo; - public ExceptionContext([NotNull] ActionContext actionContext, [NotNull] IList filters) + public ExceptionContext(ActionContext actionContext, IList filters) : base(actionContext, filters) { } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterContext.cs index a37a55c5e7..838ae8ad60 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterContext.cs @@ -1,21 +1,26 @@ // 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 { public abstract class FilterContext : ActionContext { public FilterContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters) + ActionContext actionContext, + IList filters) : base(actionContext) { + if (filters == null) + { + throw new ArgumentNullException(nameof(filters)); + } + Filters = filters; } - public virtual IList Filters { get; private set; } + public virtual IList Filters { get; } } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterDescriptor.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterDescriptor.cs index 9e2e75034a..637e9d14a3 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterDescriptor.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterDescriptor.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.Filters { @@ -33,8 +33,13 @@ namespace Microsoft.AspNet.Mvc.Filters /// will be taken from . Otherwise the value /// of will default to 0. /// - public FilterDescriptor([NotNull] IFilterMetadata filter, int filterScope) + public FilterDescriptor(IFilterMetadata filter, int filterScope) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } + Filter = filter; Scope = filterScope; diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterItem.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterItem.cs index b8142c9a55..d42965805d 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterItem.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterItem.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.Diagnostics; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -10,14 +10,24 @@ namespace Microsoft.AspNet.Mvc.Filters [DebuggerDisplay("FilterItem: {Filter}")] public class FilterItem { - public FilterItem([NotNull] FilterDescriptor descriptor) + public FilterItem(FilterDescriptor descriptor) { + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + Descriptor = descriptor; } - public FilterItem([NotNull] FilterDescriptor descriptor, [NotNull] IFilterMetadata filter) + public FilterItem(FilterDescriptor descriptor, IFilterMetadata filter) : this(descriptor) { + if (filter == null) + { + throw new ArgumentNullException(nameof(filter)); + } + Filter = filter; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterProviderContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterProviderContext.cs index c3b77f6edd..6a67c45a85 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterProviderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/FilterProviderContext.cs @@ -1,15 +1,25 @@ // 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 { public class FilterProviderContext { - public FilterProviderContext([NotNull] ActionContext actionContext, [NotNull] IList items) + public FilterProviderContext(ActionContext actionContext, IList items) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + ActionContext = actionContext; Results = items; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IActionFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IActionFilter.cs index 498865f69b..517a1d8db7 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IActionFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IActionFilter.cs @@ -1,14 +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 Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.Filters { public interface IActionFilter : IFilterMetadata { - void OnActionExecuting([NotNull] ActionExecutingContext context); + void OnActionExecuting(ActionExecutingContext context); - void OnActionExecuted([NotNull] ActionExecutedContext context); + void OnActionExecuted(ActionExecutedContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncActionFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncActionFilter.cs index d9d2e814e5..6ed40d320d 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncActionFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncActionFilter.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { public interface IAsyncActionFilter : IFilterMetadata { - Task OnActionExecutionAsync([NotNull] ActionExecutingContext context, [NotNull] ActionExecutionDelegate next); + Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncAuthorizationFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncAuthorizationFilter.cs index a8655ac4d6..9f246391ab 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncAuthorizationFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncAuthorizationFilter.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { public interface IAsyncAuthorizationFilter : IFilterMetadata { - Task OnAuthorizationAsync([NotNull] AuthorizationContext context); + Task OnAuthorizationAsync(AuthorizationContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncExceptionFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncExceptionFilter.cs index 7f0ac76aab..d025946040 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncExceptionFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncExceptionFilter.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { public interface IAsyncExceptionFilter : IFilterMetadata { - Task OnExceptionAsync([NotNull] ExceptionContext context); + Task OnExceptionAsync(ExceptionContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResourceFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResourceFilter.cs index 0b864095f0..9d337ca26b 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResourceFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResourceFilter.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 Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Filters /// A which will complete when the remainder of the pipeline completes. /// Task OnResourceExecutionAsync( - [NotNull] ResourceExecutingContext context, - [NotNull] ResourceExecutionDelegate next); + ResourceExecutingContext context, + ResourceExecutionDelegate next); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResultFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResultFilter.cs index 4637fa172e..d0dffee03e 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResultFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAsyncResultFilter.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { public interface IAsyncResultFilter : IFilterMetadata { - Task OnResultExecutionAsync([NotNull] ResultExecutingContext context, [NotNull] ResultExecutionDelegate next); + Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAuthorizationFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAuthorizationFilter.cs index e8bd2b96ca..d71d275091 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAuthorizationFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IAuthorizationFilter.cs @@ -1,12 +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 Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.Filters { public interface IAuthorizationFilter : IFilterMetadata { - void OnAuthorization([NotNull] AuthorizationContext context); + void OnAuthorization(AuthorizationContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IExceptionFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IExceptionFilter.cs index 3dc4e2d649..8085938d01 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IExceptionFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IExceptionFilter.cs @@ -1,12 +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 Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.Filters { public interface IExceptionFilter : IFilterMetadata { - void OnException([NotNull] ExceptionContext context); + void OnException(ExceptionContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterFactory.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterFactory.cs index c6be40aa1c..1e65313afe 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterFactory.cs @@ -2,12 +2,11 @@ // 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.Filters { public interface IFilterFactory : IFilterMetadata { - IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider); + IFilterMetadata CreateInstance(IServiceProvider serviceProvider); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterProvider.cs index 0352adfe58..ea5b228073 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IFilterProvider.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.Filters { public interface IFilterProvider @@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Filters /// int Order { get; } - void OnProvidersExecuting([NotNull] FilterProviderContext context); + void OnProvidersExecuting(FilterProviderContext context); - void OnProvidersExecuted([NotNull] FilterProviderContext context); + void OnProvidersExecuted(FilterProviderContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResourceFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResourceFilter.cs index dbc83cb2d2..f4c4665b3b 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResourceFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResourceFilter.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.Filters { /// @@ -15,12 +13,12 @@ namespace Microsoft.AspNet.Mvc.Filters /// Executes the resource filter. Called before execution of the remainder of the pipeline. /// /// The . - void OnResourceExecuting([NotNull] ResourceExecutingContext context); + void OnResourceExecuting(ResourceExecutingContext context); /// /// Executes the resource filter. Called after execution of the remainder of the pipeline. /// /// The . - void OnResourceExecuted([NotNull] ResourceExecutedContext context); + void OnResourceExecuted(ResourceExecutedContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResultFilter.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResultFilter.cs index 32ede1eb4c..c0f8949649 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResultFilter.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/IResultFilter.cs @@ -1,14 +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 Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.Filters { public interface IResultFilter : IFilterMetadata { - void OnResultExecuting([NotNull] ResultExecutingContext context); + void OnResultExecuting(ResultExecutingContext context); - void OnResultExecuted([NotNull] ResultExecutedContext context); + void OnResultExecuted(ResultExecutedContext context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutedContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutedContext.cs index 87fe7522dd..e106a98ff8 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutedContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutedContext.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { @@ -14,12 +13,17 @@ namespace Microsoft.AspNet.Mvc.Filters private ExceptionDispatchInfo _exceptionDispatchInfo; public ResultExecutedContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters, - [NotNull] IActionResult result, + ActionContext actionContext, + IList filters, + IActionResult result, object controller) : base(actionContext, filters) { + if (result == null) + { + throw new ArgumentNullException(nameof(result)); + } + Result = result; Controller = controller; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutingContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutingContext.cs index 88cb7ba4e1..99b77aa797 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutingContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Filters/ResultExecutingContext.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 Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Filters { public class ResultExecutingContext : FilterContext { public ResultExecutingContext( - [NotNull] ActionContext actionContext, - [NotNull] IList filters, - [NotNull] IActionResult result, + ActionContext actionContext, + IList filters, + IActionResult result, object controller) : base(actionContext, filters) { diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/Formatters/InputFormatterContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/Formatters/InputFormatterContext.cs index 16ea436c20..8314fb041e 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/Formatters/InputFormatterContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/Formatters/InputFormatterContext.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Formatters { @@ -27,11 +26,31 @@ namespace Microsoft.AspNet.Mvc.Formatters /// The of the model to deserialize. /// public InputFormatterContext( - [NotNull] HttpContext httpContext, - [NotNull] string modelName, - [NotNull] ModelStateDictionary modelState, - [NotNull] Type modelType) + HttpContext httpContext, + string modelName, + ModelStateDictionary modelState, + Type modelType) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (modelName == null) + { + throw new ArgumentNullException(nameof(modelName)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + HttpContext = httpContext; ModelName = modelName; ModelState = modelState; diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/BindingSource.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/BindingSource.cs index b25a4bae94..b94b06d437 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/BindingSource.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/BindingSource.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -96,8 +95,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// A value indicating whether or not the data comes from the HTTP request. /// - public BindingSource([NotNull] string id, string displayName, bool isGreedy, bool isFromRequest) + public BindingSource(string id, string displayName, bool isGreedy, bool isFromRequest) { + if (id == null) + { + throw new ArgumentNullException(nameof(id)); + } + Id = id; DisplayName = displayName; IsGreedy = isGreedy; @@ -158,8 +162,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// This distinction is important as the left-hand-side may be a composite, but the right /// may not. /// - public virtual bool CanAcceptDataFrom([NotNull] BindingSource bindingSource) + public virtual bool CanAcceptDataFrom(BindingSource bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + if (bindingSource is CompositeBindingSource) { var message = Resources.FormatBindingSource_CannotBeComposite( diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/CompositeBindingSource.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/CompositeBindingSource.cs index cd4f9ebe79..354d7c067a 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/CompositeBindingSource.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/CompositeBindingSource.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -24,9 +23,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The display name for the composite source. /// A . public static CompositeBindingSource Create( - [NotNull] IEnumerable bindingSources, + IEnumerable bindingSources, string displayName) { + if (bindingSources == null) + { + throw new ArgumentNullException(nameof(bindingSources)); + } + foreach (var bindingSource in bindingSources) { if (bindingSource.IsGreedy) @@ -59,11 +63,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } private CompositeBindingSource( - [NotNull] string id, - string displayName, - [NotNull] IEnumerable bindingSources) + string id, + string displayName, + IEnumerable bindingSources) : base(id, displayName, isGreedy: false, isFromRequest: true) { + if (id == null) + { + throw new ArgumentNullException(nameof(id)); + } + + if (bindingSources == null) + { + throw new ArgumentNullException(nameof(bindingSources)); + } + BindingSources = bindingSources; } @@ -73,8 +87,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding public IEnumerable BindingSources { get; } /// - public override bool CanAcceptDataFrom([NotNull] BindingSource bindingSource) + public override bool CanAcceptDataFrom(BindingSource bindingSource) { + if (bindingSource == null) + { + throw new ArgumentNullException(nameof(bindingSource)); + } + if (bindingSource is CompositeBindingSource) { var message = Resources.FormatBindingSource_CannotBeComposite( diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IModelMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IModelMetadataProvider.cs index 4cf3957734..9c6501c0c0 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IModelMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IModelMetadataProvider.cs @@ -3,15 +3,13 @@ using System; using System.Collections.Generic; -using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { public interface IModelMetadataProvider { - ModelMetadata GetMetadataForType([NotNull] Type modelType); + ModelMetadata GetMetadataForType(Type modelType); - IEnumerable GetMetadataForProperties([NotNull] Type modelType); + IEnumerable GetMetadataForProperties(Type modelType); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IValueProviderFactory.cs index cf7ba74b3c..66b8876c39 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/IValueProviderFactory.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 Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -15,6 +14,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// A that when completed will yield a instance or null. /// - Task GetValueProviderAsync([NotNull] ValueProviderFactoryContext context); + Task GetValueProviderAsync(ValueProviderFactoryContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Metadata/ModelMetadataIdentity.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Metadata/ModelMetadataIdentity.cs index 9f2a2e7712..f1ff1640d2 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Metadata/ModelMetadataIdentity.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Metadata/ModelMetadataIdentity.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Mvc.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// /// The model . /// A . - public static ModelMetadataIdentity ForType([NotNull] Type modelType) + public static ModelMetadataIdentity ForType(Type modelType) { + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + return new ModelMetadataIdentity() { ModelType = modelType, @@ -33,10 +37,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata /// The container type of the model property. /// A . public static ModelMetadataIdentity ForProperty( - [NotNull] Type modelType, + Type modelType, string name, - [NotNull] Type containerType) + Type containerType) { + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + + if (containerType == null) + { + throw new ArgumentNullException(nameof(containerType)); + } + if (string.IsNullOrEmpty(name)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(name)); diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingContext.cs index f2af63e1fd..e32b97f063 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingContext.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; using Microsoft.AspNet.Mvc.ModelBinding.Validation; namespace Microsoft.AspNet.Mvc.ModelBinding @@ -12,6 +11,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// public class ModelBindingContext { + private string _fieldName; + private ModelMetadata _modelMetadata; + private string _modelName; + private ModelStateDictionary _modelState; + private OperationBindingContext _operationBindingContext; + private IValueProvider _valueProvider; + /// /// Initializes a new instance of the class. /// @@ -30,12 +36,32 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The name of the property or parameter being bound. /// A new instance of . public static ModelBindingContext CreateBindingContext( - [NotNull] OperationBindingContext operationBindingContext, - [NotNull] ModelStateDictionary modelState, - [NotNull] ModelMetadata metadata, + OperationBindingContext operationBindingContext, + ModelStateDictionary modelState, + ModelMetadata metadata, BindingInfo bindingInfo, - [NotNull] string modelName) + string modelName) { + if (operationBindingContext == null) + { + throw new ArgumentNullException(nameof(operationBindingContext)); + } + + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + if (modelName == null) + { + throw new ArgumentNullException(nameof(modelName)); + } + var binderModelName = bindingInfo?.BinderModelName ?? metadata.BinderModelName; var propertyPredicateProvider = bindingInfo?.PropertyBindingPredicateProvider ?? metadata.PropertyBindingPredicateProvider; @@ -66,12 +92,32 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } public static ModelBindingContext CreateChildBindingContext( - [NotNull] ModelBindingContext parent, - [NotNull] ModelMetadata modelMetadata, - [NotNull] string fieldName, - [NotNull] string modelName, + ModelBindingContext parent, + ModelMetadata modelMetadata, + string fieldName, + string modelName, object model) { + if (parent == null) + { + throw new ArgumentNullException(nameof(parent)); + } + + if (modelMetadata == null) + { + throw new ArgumentNullException(nameof(modelMetadata)); + } + + if (fieldName == null) + { + throw new ArgumentNullException(nameof(fieldName)); + } + + if (modelName == null) + { + throw new ArgumentNullException(nameof(modelName)); + } + return new ModelBindingContext() { ModelState = parent.ModelState, @@ -93,12 +139,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// Represents the associated with this context. /// - public OperationBindingContext OperationBindingContext { get; [param:NotNull] set; } + public OperationBindingContext OperationBindingContext + { + get { return _operationBindingContext; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _operationBindingContext = value; + } + } /// /// Gets or sets the name of the current field being bound. /// - public string FieldName { get; [param: NotNull] set; } + public string FieldName + { + get { return _fieldName; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _fieldName = value; + } + } /// /// Gets or sets the model value for the current operation. @@ -112,19 +182,55 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// Gets or sets the metadata for the model associated with this context. /// - public ModelMetadata ModelMetadata { get; [param: NotNull] set; } + public ModelMetadata ModelMetadata + { + get { return _modelMetadata; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _modelMetadata = value; + } + } /// /// Gets or sets the name of the model. This property is used as a key for looking up values in /// during model binding. /// - public string ModelName { get; [param: NotNull] set; } + public string ModelName + { + get { return _modelName; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _modelName = value; + } + } /// /// Gets or sets the used to capture values /// for properties in the object graph of the model when binding. /// - public ModelStateDictionary ModelState { get; [param: NotNull] set; } + public ModelStateDictionary ModelState + { + get { return _modelState; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _modelState = value; + } + } /// /// Gets the type of the model. @@ -171,7 +277,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// Gets or sets the associated with this context. /// - public IValueProvider ValueProvider { get; [param: NotNull] set; } + public IValueProvider ValueProvider + { + get { return _valueProvider; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _valueProvider = value; + } + } /// /// Gets or sets a predicate which will be evaluated for each property to determine if the property diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs index 94807b10d6..5acb235d53 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs @@ -29,8 +29,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The key of the current model binding operation. /// A representing a failed model binding operation. - public static ModelBindingResult Failed([NotNull] string key) + public static ModelBindingResult Failed(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return new ModelBindingResult(key, model: null, isModelSet: false); } @@ -39,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The key of the current model binding operation. /// A completed representing a failed model binding operation. - public static Task FailedAsync([NotNull] string key) + public static Task FailedAsync(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return Task.FromResult(Failed(key)); } @@ -51,9 +61,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The model value. May be null. /// A representing a successful model bind. public static ModelBindingResult Success( - [NotNull] string key, + string key, object model) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return new ModelBindingResult(key, model, isModelSet: true); } @@ -65,9 +80,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The model value. May be null. /// A completed representing a successful model bind. public static Task SuccessAsync( - [NotNull] string key, + string key, object model) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return Task.FromResult(Success(key, model)); } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelError.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelError.cs index 60ec26f187..9002fc84ea 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelError.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelError.cs @@ -2,20 +2,28 @@ // 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 { public class ModelError { - public ModelError([NotNull]Exception exception) + public ModelError(Exception exception) : this(exception, errorMessage: null) { + if (exception == null) + { + throw new ArgumentNullException(nameof(exception)); + } } - public ModelError([NotNull]Exception exception, string errorMessage) + public ModelError(Exception exception, string errorMessage) : this(errorMessage) { + if (exception == null) + { + throw new ArgumentNullException(nameof(exception)); + } + Exception = exception; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelErrorCollection.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelErrorCollection.cs index 2176b26fd8..a4df159b8d 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelErrorCollection.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelErrorCollection.cs @@ -3,19 +3,28 @@ using System; using System.Collections.ObjectModel; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { public class ModelErrorCollection : Collection { - public void Add([NotNull]Exception exception) + public void Add(Exception exception) { + if (exception == null) + { + throw new ArgumentNullException(nameof(exception)); + } + Add(new ModelError(exception)); } - public void Add([NotNull]string errorMessage) + public void Add(string errorMessage) { + if (errorMessage == null) + { + throw new ArgumentNullException(nameof(errorMessage)); + } + Add(new ModelError(errorMessage)); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelMetadata.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelMetadata.cs index c8f9aaf83f..5e3039322b 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelMetadata.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Creates a new . /// /// The . - protected ModelMetadata([NotNull] ModelMetadataIdentity identity) + protected ModelMetadata(ModelMetadataIdentity identity) { Identity = identity; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs index cc783adda9..88ac5170c8 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelPropertyCollection.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { @@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Creates a new . /// /// The properties. - public ModelPropertyCollection([NotNull] IEnumerable properties) + public ModelPropertyCollection(IEnumerable properties) { + if (properties == null) + { + throw new ArgumentNullException(nameof(properties)); + } + _properties = new List(properties); } @@ -43,11 +47,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// The instance for the property specified by , or null /// if no match can be found. /// - public ModelMetadata this[[NotNull] string propertyName] + public ModelMetadata this[string propertyName] { - get { + if (propertyName == null) + { + throw new ArgumentNullException(nameof(propertyName)); + } + foreach (var property in _properties) { if (string.Equals(property.PropertyName, propertyName, StringComparison.Ordinal)) diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs index d4aeec8ed3..1055054016 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs @@ -4,7 +4,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Globalization; using System.Linq; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.Framework.Internal; @@ -49,10 +48,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// from the specified . /// /// The to copy values from. - public ModelStateDictionary([NotNull] ModelStateDictionary dictionary) + public ModelStateDictionary(ModelStateDictionary dictionary) { - _innerDictionary = new CopyOnWriteDictionary(dictionary, - StringComparer.OrdinalIgnoreCase); + if (dictionary == null) + { + throw new ArgumentNullException(nameof(dictionary)); + } + + _innerDictionary = new CopyOnWriteDictionary( + dictionary, + StringComparer.OrdinalIgnoreCase); MaxAllowedErrors = dictionary.MaxAllowedErrors; ErrorCount = dictionary.ErrorCount; @@ -152,16 +157,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public ModelState this[[NotNull] string key] + public ModelState this[string key] { get { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + ModelState value; _innerDictionary.TryGetValue(key, out value); return value; } set { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + if (value == null) { throw new ArgumentNullException(nameof(value)); @@ -185,8 +200,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The key of the to add errors to. /// The to add. - public void AddModelError([NotNull] string key, [NotNull] Exception exception) + public void AddModelError(string key, Exception exception) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (exception == null) + { + throw new ArgumentNullException(nameof(exception)); + } + TryAddModelError(key, exception); } @@ -201,8 +226,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// True if the given error was added, false if the error was ignored. /// See . /// - public bool TryAddModelError([NotNull] string key, [NotNull] Exception exception) + public bool TryAddModelError(string key, Exception exception) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (exception == null) + { + throw new ArgumentNullException(nameof(exception)); + } + if (ErrorCount >= MaxAllowedErrors - 1) { EnsureMaxErrorsReachedRecorded(); @@ -241,8 +276,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The key of the to add errors to. /// The error message to add. - public void AddModelError([NotNull] string key, [NotNull] string errorMessage) + public void AddModelError(string key, string errorMessage) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (errorMessage == null) + { + throw new ArgumentNullException(nameof(errorMessage)); + } + TryAddModelError(key, errorMessage); } @@ -257,8 +302,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// True if the given error was added, false if the error was ignored. /// See . /// - public bool TryAddModelError([NotNull] string key, [NotNull] string errorMessage) + public bool TryAddModelError(string key, string errorMessage) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (errorMessage == null) + { + throw new ArgumentNullException(nameof(errorMessage)); + } + if (ErrorCount >= MaxAllowedErrors - 1) { EnsureMaxErrorsReachedRecorded(); @@ -281,8 +336,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Returns if no entries are found for the specified /// key, if at least one instance is found with one or more model /// state errors; otherwise. - public ModelValidationState GetFieldValidationState([NotNull] string key) + public ModelValidationState GetFieldValidationState(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + var entries = FindKeysWithPrefix(key); if (!entries.Any()) { @@ -299,8 +359,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// Returns if no entry is found for the specified /// key, if an instance is found with one or more model /// state errors; otherwise. - public ModelValidationState GetValidationState([NotNull] string key) + public ModelValidationState GetValidationState(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + ModelState validationState; if (TryGetValue(key, out validationState)) { @@ -315,8 +380,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// as . /// /// The key of the to mark as valid. - public void MarkFieldValid([NotNull] string key) + public void MarkFieldValid(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + var modelState = GetModelStateForKey(key); if (modelState.ValidationState == ModelValidationState.Invalid) { @@ -331,8 +401,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// as . /// /// The key of the to mark as skipped. - public void MarkFieldSkipped([NotNull] string key) + public void MarkFieldSkipped(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + var modelState = GetModelStateForKey(key); if (modelState.ValidationState == ModelValidationState.Invalid) { @@ -369,8 +444,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// The values of in a comma-separated . /// - public void SetModelValue([NotNull] string key, object rawValue, string attemptedValue) + public void SetModelValue(string key, object rawValue, string attemptedValue) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + var modelState = GetModelStateForKey(key); modelState.RawValue = rawValue; modelState.AttemptedValue = attemptedValue; @@ -383,8 +463,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// /// A with data for the entry. /// - public void SetModelValue([NotNull] string key, ValueProviderResult valueProviderResult) + public void SetModelValue(string key, ValueProviderResult valueProviderResult) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + // Avoid creating a new array for rawValue if there's only one value. object rawValue; if (valueProviderResult == ValueProviderResult.None) @@ -411,7 +496,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { // If key is null or empty, clear all entries in the dictionary // else just clear the ones that have key as prefix - var entries = (string.IsNullOrEmpty(key)) ? + var entries = (string.IsNullOrEmpty(key)) ? _innerDictionary : FindKeysWithPrefix(key); foreach (var entry in entries) @@ -421,8 +506,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - private ModelState GetModelStateForKey([NotNull] string key) + private ModelState GetModelStateForKey(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + ModelState modelState; if (!TryGetValue(key, out modelState)) { @@ -477,8 +567,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public void Add([NotNull] string key, [NotNull] ModelState value) + public void Add(string key, ModelState value) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _innerDictionary.Add(key, value); } @@ -495,14 +595,24 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public bool ContainsKey([NotNull] string key) + public bool ContainsKey(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _innerDictionary.ContainsKey(key); } /// - public void CopyTo([NotNull] KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + _innerDictionary.CopyTo(array, arrayIndex); } @@ -513,14 +623,24 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } /// - public bool Remove([NotNull] string key) + public bool Remove(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _innerDictionary.Remove(key); } /// - public bool TryGetValue([NotNull] string key, out ModelState value) + public bool TryGetValue(string key, out ModelState value) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _innerDictionary.TryGetValue(key, out value); } @@ -536,8 +656,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return GetEnumerator(); } - public IEnumerable> FindKeysWithPrefix([NotNull] string prefix) + public IEnumerable> FindKeysWithPrefix(string prefix) { + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + ModelState exactMatchValue; if (_innerDictionary.TryGetValue(prefix, out exactMatchValue)) { diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/TooManyModelErrorsException.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/TooManyModelErrorsException.cs index cc2f761afa..3bcb42f73f 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/TooManyModelErrorsException.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/TooManyModelErrorsException.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 { @@ -16,9 +15,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// exception . /// /// The message that describes the error. - public TooManyModelErrorsException([NotNull] string message) + public TooManyModelErrorsException(string message) : base(message) { + if (message == null) + { + throw new ArgumentNullException(nameof(message)); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ClientModelValidationContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ClientModelValidationContext.cs index 719e706a69..e1a8d30e00 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ClientModelValidationContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ClientModelValidationContext.cs @@ -2,17 +2,31 @@ // 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 { public class ClientModelValidationContext { public ClientModelValidationContext( - [NotNull] ModelMetadata metadata, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IServiceProvider requestServices) + ModelMetadata metadata, + IModelMetadataProvider metadataProvider, + IServiceProvider requestServices) { + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (requestServices == null) + { + throw new ArgumentNullException(nameof(requestServices)); + } + ModelMetadata = metadata; MetadataProvider = metadataProvider; RequestServices = requestServices; diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidator.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidator.cs index 37aa768000..dc3e32b6fd 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidator.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidator.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { public interface IClientModelValidator { - IEnumerable GetClientValidationRules([NotNull] ClientModelValidationContext context); + IEnumerable GetClientValidationRules(ClientModelValidationContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidatorProvider.cs index 20d92eeaed..ea697e099a 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/IClientModelValidatorProvider.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.Validation { /// @@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation /// by updating . /// /// The associated with this call. - void GetValidators([NotNull] ClientValidatorProviderContext context); + void GetValidators(ClientValidatorProviderContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ModelClientValidationRule.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ModelClientValidationRule.cs index 306576930b..3a2649ba82 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ModelClientValidationRule.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/Validation/ModelClientValidationRule.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { @@ -12,15 +11,29 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation private readonly Dictionary _validationParameters = new Dictionary(StringComparer.Ordinal); - public ModelClientValidationRule([NotNull] string errorMessage) + public ModelClientValidationRule(string errorMessage) : this(validationType: string.Empty, errorMessage: errorMessage) { + if (errorMessage == null) + { + throw new ArgumentNullException(nameof(errorMessage)); + } } public ModelClientValidationRule( - [NotNull] string validationType, - [NotNull] string errorMessage) + string validationType, + string errorMessage) { + if (validationType == null) + { + throw new ArgumentNullException(nameof(validationType)); + } + + if (errorMessage == null) + { + throw new ArgumentNullException(nameof(errorMessage)); + } + ValidationType = validationType; ErrorMessage = errorMessage; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ValueProviderFactoryContext.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ValueProviderFactoryContext.cs index 5f454cbb72..d06b0469e8 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ValueProviderFactoryContext.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ValueProviderFactoryContext.cs @@ -1,18 +1,28 @@ // 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.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ModelBinding { public class ValueProviderFactoryContext { public ValueProviderFactoryContext( - [NotNull] HttpContext httpContext, - [NotNull] IDictionary routeValues) + HttpContext httpContext, + IDictionary routeValues) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (routeValues == null) + { + throw new ArgumentNullException(nameof(routeValues)); + } + HttpContext = httpContext; RouteValues = routeValues; } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/project.json b/src/Microsoft.AspNet.Mvc.Abstractions/project.json index f1d0a721ef..aea2b56f1c 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/project.json +++ b/src/Microsoft.AspNet.Mvc.Abstractions/project.json @@ -22,10 +22,6 @@ "version": "1.0.0-*", "type": "build" }, - "Microsoft.Framework.NotNullAttribute.Sources": { - "version": "1.0.0-*", - "type": "build" - }, "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" diff --git a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs index 20491452f8..20a1f0c10e 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServiceCollectionExtensions.cs @@ -4,19 +4,28 @@ using System; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { public static class MvcServiceCollectionExtensions { - public static IMvcBuilder AddMvc([NotNull] this IServiceCollection services) + public static IMvcBuilder AddMvc(this IServiceCollection services) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + return AddMvc(services, setupAction: null); } - public static IMvcBuilder AddMvc([NotNull] this IServiceCollection services, Action setupAction) + public static IMvcBuilder AddMvc(this IServiceCollection services, Action setupAction) { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + var builder = services.AddMvcCore(); builder.AddApiExplorer(); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs index 386dbfee01..bdf049490c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionArgumentBinderTests.cs @@ -210,6 +210,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var mockValidator = new Mock(MockBehavior.Strict); @@ -305,6 +306,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var mockValidator = new Mock(MockBehavior.Strict); @@ -413,6 +415,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var argumentBinder = GetArgumentBinder(); @@ -451,6 +454,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; var argumentBinder = GetArgumentBinder(); @@ -600,6 +604,7 @@ namespace Microsoft.AspNet.Mvc.Controllers var actionBindingContext = new ActionBindingContext { ModelBinder = binder.Object, + ValueProvider = new SimpleValueProvider(), }; // Act diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs index 31e3d8e9dd..03f4812424 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs @@ -379,6 +379,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test ModelState = new ModelStateDictionary(), OperationBindingContext = new OperationBindingContext(), ValueProvider = new SimpleValueProvider(), + FieldName = "test-field", }; // Act @@ -528,6 +529,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test IsTopLevelObject = true, ModelMetadata = metadataProvider.GetMetadataForType(type), ModelName = "parameter", + FieldName = "parameter", ModelState = new ModelStateDictionary(), ValueProvider = valueProvider, OperationBindingContext = new OperationBindingContext diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs index b5e10a2648..1e684bdf3c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs @@ -278,7 +278,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), }, // Setting it to empty ensures that model does not get created becasue of no model name. - ModelName = "dummyName" + ModelName = "dummyName", + ModelState = new ModelStateDictionary(), } }; @@ -339,7 +340,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Setting it to empty ensures that model does not get created becasue of no model name. ModelName = "dummyName", BindingSource = modelMetadata.BindingSource, - BinderModelName = modelMetadata.BinderModelName + BinderModelName = modelMetadata.BinderModelName, + ModelState = new ModelStateDictionary(), } }; @@ -384,7 +386,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), }, // Setting it to empty ensures that model does not get created becasue of no model name. - ModelName = "dummyName" + ModelName = "dummyName", + ModelState = new ModelStateDictionary(), } }; @@ -424,7 +427,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding ModelBinder = mockBinder.Object, MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), ValidatorProvider = Mock.Of() - } + }, + ModelState = new ModelStateDictionary(), }; var model = new Person(); @@ -475,7 +479,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding ModelBinder = mockBinder.Object, MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), ValidatorProvider = Mock.Of() - } + }, + ModelState = new ModelStateDictionary(), }; var model = new Person(); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs index e434e9fe66..f52d1e7566 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs @@ -293,7 +293,8 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests { BinderModelName = "CustomParameter", }, - ParameterType = typeof(Person2) + ParameterType = typeof(Person2), + Name = "param-name", }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext( @@ -352,7 +353,8 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests { BinderModelName = "CustomParameter", }, - ParameterType = typeof(Person3) + ParameterType = typeof(Person3), + Name = "param-name", }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(