Replacing NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-10-01 08:23:21 -07:00
parent 3a876e387f
commit 5a705d820d
56 changed files with 695 additions and 212 deletions

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.Abstractions namespace Microsoft.AspNet.Mvc.Abstractions
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Abstractions
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="actionDescriptor">The action descriptor.</param> /// <param name="actionDescriptor">The action descriptor.</param>
/// <returns>The property or the default value of <typeparamref name="T"/>.</returns> /// <returns>The property or the default value of <typeparamref name="T"/>.</returns>
public static T GetProperty<T>([NotNull] this ActionDescriptor actionDescriptor) public static T GetProperty<T>(this ActionDescriptor actionDescriptor)
{ {
if (actionDescriptor == null)
{
throw new ArgumentNullException(nameof(actionDescriptor));
}
object value; object value;
if (actionDescriptor.Properties.TryGetValue(typeof(T), out value)) if (actionDescriptor.Properties.TryGetValue(typeof(T), out value))
{ {
@ -37,8 +42,18 @@ namespace Microsoft.AspNet.Mvc.Abstractions
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="actionDescriptor">The action descriptor.</param> /// <param name="actionDescriptor">The action descriptor.</param>
/// <param name="value">The value of the property.</param> /// <param name="value">The value of the property.</param>
public static void SetProperty<T>([NotNull] this ActionDescriptor actionDescriptor, [NotNull] T value) public static void SetProperty<T>(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; actionDescriptor.Properties[typeof(T)] = value;
} }
} }

View File

@ -1,14 +1,19 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.Abstractions namespace Microsoft.AspNet.Mvc.Abstractions
{ {
public class ActionInvokerProviderContext public class ActionInvokerProviderContext
{ {
public ActionInvokerProviderContext([NotNull] ActionContext actionContext) public ActionInvokerProviderContext(ActionContext actionContext)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
ActionContext = actionContext; ActionContext = actionContext;
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.Abstractions
{ {
public interface IActionDescriptorProvider public interface IActionDescriptorProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Abstractions
/// </remarks> /// </remarks>
int Order { get; } int Order { get; }
void OnProvidersExecuting([NotNull] ActionDescriptorProviderContext context); void OnProvidersExecuting(ActionDescriptorProviderContext context);
void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context); void OnProvidersExecuted(ActionDescriptorProviderContext context);
} }
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.Abstractions
{ {
public interface IActionInvokerProvider public interface IActionInvokerProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Abstractions
/// </remarks> /// </remarks>
int Order { get; } int Order { get; }
void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context); void OnProvidersExecuting(ActionInvokerProviderContext context);
void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context); void OnProvidersExecuted(ActionInvokerProviderContext context);
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.ActionConstraints namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
@ -15,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
/// Creates a new <see cref="ActionConstraintItem"/>. /// Creates a new <see cref="ActionConstraintItem"/>.
/// </summary> /// </summary>
/// <param name="metadata">The <see cref="IActionConstraintMetadata"/> instance.</param> /// <param name="metadata">The <see cref="IActionConstraintMetadata"/> instance.</param>
public ActionConstraintItem([NotNull] IActionConstraintMetadata metadata) public ActionConstraintItem(IActionConstraintMetadata metadata)
{ {
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}
Metadata = metadata; Metadata = metadata;
} }

View File

@ -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. // 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.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ActionConstraints namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
@ -19,10 +19,25 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
/// <param name="action">The <see cref="ActionDescriptor"/> for which constraints are being created.</param> /// <param name="action">The <see cref="ActionDescriptor"/> for which constraints are being created.</param>
/// <param name="items">The list of <see cref="ActionConstraintItem"/> objects.</param> /// <param name="items">The list of <see cref="ActionConstraintItem"/> objects.</param>
public ActionConstraintProviderContext( public ActionConstraintProviderContext(
[NotNull] HttpContext context, HttpContext context,
[NotNull] ActionDescriptor action, ActionDescriptor action,
[NotNull] IList<ActionConstraintItem> items) IList<ActionConstraintItem> 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; HttpContext = context;
Action = action; Action = action;
Results = items; Results = items;

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ActionConstraints namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
/// <param name="constraints"> /// <param name="constraints">
/// The list of <see cref="IActionConstraint"/> instances associated with <paramref name="action"/>. /// The list of <see cref="IActionConstraint"/> instances associated with <paramref name="action"/>.
/// </param> /// </param>
public ActionSelectorCandidate([NotNull] ActionDescriptor action, IReadOnlyList<IActionConstraint> constraints) public ActionSelectorCandidate(ActionDescriptor action, IReadOnlyList<IActionConstraint> constraints)
{ {
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
Action = action; Action = action;
Constraints = constraints; Constraints = constraints;
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
public interface IActionConstraintProvider public interface IActionConstraintProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
/// </remarks> /// </remarks>
int Order { get; } int Order { get; }
void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context); void OnProvidersExecuting(ActionConstraintProviderContext context);
void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context); void OnProvidersExecuted(ActionConstraintProviderContext context);
} }
} }

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -29,13 +29,17 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="ActionContext"/>. /// Creates a new <see cref="ActionContext"/>.
/// </summary> /// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> to copy.</param> /// <param name="actionContext">The <see cref="ActionContext"/> to copy.</param>
public ActionContext([NotNull] ActionContext actionContext) public ActionContext(ActionContext actionContext)
: this( : this(
actionContext.HttpContext, actionContext.HttpContext,
actionContext.RouteData, actionContext.RouteData,
actionContext.ActionDescriptor, actionContext.ActionDescriptor,
actionContext.ModelState) actionContext.ModelState)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
} }
/// <summary> /// <summary>
@ -45,9 +49,9 @@ namespace Microsoft.AspNet.Mvc
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param> /// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
/// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param> /// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
public ActionContext( public ActionContext(
[NotNull] HttpContext httpContext, HttpContext httpContext,
[NotNull] RouteData routeData, RouteData routeData,
[NotNull] ActionDescriptor actionDescriptor) ActionDescriptor actionDescriptor)
: this(httpContext, routeData, actionDescriptor, new ModelStateDictionary()) : this(httpContext, routeData, actionDescriptor, new ModelStateDictionary())
{ {
} }
@ -60,11 +64,31 @@ namespace Microsoft.AspNet.Mvc
/// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param> /// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/>.</param> /// <param name="modelState">The <see cref="ModelStateDictionary"/>.</param>
public ActionContext( public ActionContext(
[NotNull] HttpContext httpContext, HttpContext httpContext,
[NotNull] RouteData routeData, RouteData routeData,
[NotNull] ActionDescriptor actionDescriptor, ActionDescriptor actionDescriptor,
[NotNull] ModelStateDictionary modelState) 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; HttpContext = httpContext;
RouteData = routeData; RouteData = routeData;
ActionDescriptor = actionDescriptor; ActionDescriptor = actionDescriptor;

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -14,8 +13,8 @@ namespace Microsoft.AspNet.Mvc.Filters
private ExceptionDispatchInfo _exceptionDispatchInfo; private ExceptionDispatchInfo _exceptionDispatchInfo;
public ActionExecutedContext( public ActionExecutedContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters, IList<IFilterMetadata> filters,
object controller) object controller)
: base(actionContext, filters) : base(actionContext, filters)
{ {

View File

@ -1,20 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public class ActionExecutingContext : FilterContext public class ActionExecutingContext : FilterContext
{ {
public ActionExecutingContext( public ActionExecutingContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters, IList<IFilterMetadata> filters,
[NotNull] IDictionary<string, object> actionArguments, IDictionary<string, object> actionArguments,
object controller) object controller)
: base(actionContext, filters) : base(actionContext, filters)
{ {
if (actionArguments == null)
{
throw new ArgumentNullException(nameof(actionArguments));
}
ActionArguments = actionArguments; ActionArguments = actionArguments;
Controller = controller; Controller = controller;
} }

View File

@ -1,16 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public class AuthorizationContext : FilterContext public class AuthorizationContext : FilterContext
{ {
public AuthorizationContext( public AuthorizationContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters) IList<IFilterMetadata> filters)
: base(actionContext, filters) : base(actionContext, filters)
{ {
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -13,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.Filters
private Exception _exception; private Exception _exception;
private ExceptionDispatchInfo _exceptionDispatchInfo; private ExceptionDispatchInfo _exceptionDispatchInfo;
public ExceptionContext([NotNull] ActionContext actionContext, [NotNull] IList<IFilterMetadata> filters) public ExceptionContext(ActionContext actionContext, IList<IFilterMetadata> filters)
: base(actionContext, filters) : base(actionContext, filters)
{ {
} }

View File

@ -1,21 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public abstract class FilterContext : ActionContext public abstract class FilterContext : ActionContext
{ {
public FilterContext( public FilterContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters) IList<IFilterMetadata> filters)
: base(actionContext) : base(actionContext)
{ {
if (filters == null)
{
throw new ArgumentNullException(nameof(filters));
}
Filters = filters; Filters = filters;
} }
public virtual IList<IFilterMetadata> Filters { get; private set; } public virtual IList<IFilterMetadata> Filters { get; }
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -33,8 +33,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Order"/> will be taken from <see cref="IOrderedFilter.Order"/>. Otherwise the value /// <see cref="Order"/> will be taken from <see cref="IOrderedFilter.Order"/>. Otherwise the value
/// of <see cref="Order"/> will default to <c>0</c>. /// of <see cref="Order"/> will default to <c>0</c>.
/// </remarks> /// </remarks>
public FilterDescriptor([NotNull] IFilterMetadata filter, int filterScope) public FilterDescriptor(IFilterMetadata filter, int filterScope)
{ {
if (filter == null)
{
throw new ArgumentNullException(nameof(filter));
}
Filter = filter; Filter = filter;
Scope = filterScope; Scope = filterScope;

View File

@ -1,8 +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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -10,14 +10,24 @@ namespace Microsoft.AspNet.Mvc.Filters
[DebuggerDisplay("FilterItem: {Filter}")] [DebuggerDisplay("FilterItem: {Filter}")]
public class FilterItem public class FilterItem
{ {
public FilterItem([NotNull] FilterDescriptor descriptor) public FilterItem(FilterDescriptor descriptor)
{ {
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
Descriptor = descriptor; Descriptor = descriptor;
} }
public FilterItem([NotNull] FilterDescriptor descriptor, [NotNull] IFilterMetadata filter) public FilterItem(FilterDescriptor descriptor, IFilterMetadata filter)
: this(descriptor) : this(descriptor)
{ {
if (filter == null)
{
throw new ArgumentNullException(nameof(filter));
}
Filter = filter; Filter = filter;
} }

View File

@ -1,15 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public class FilterProviderContext public class FilterProviderContext
{ {
public FilterProviderContext([NotNull] ActionContext actionContext, [NotNull] IList<FilterItem> items) public FilterProviderContext(ActionContext actionContext, IList<FilterItem> items)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
ActionContext = actionContext; ActionContext = actionContext;
Results = items; Results = items;
} }

View File

@ -1,14 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IActionFilter : IFilterMetadata public interface IActionFilter : IFilterMetadata
{ {
void OnActionExecuting([NotNull] ActionExecutingContext context); void OnActionExecuting(ActionExecutingContext context);
void OnActionExecuted([NotNull] ActionExecutedContext context); void OnActionExecuted(ActionExecutedContext context);
} }
} }

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IAsyncActionFilter : IFilterMetadata public interface IAsyncActionFilter : IFilterMetadata
{ {
Task OnActionExecutionAsync([NotNull] ActionExecutingContext context, [NotNull] ActionExecutionDelegate next); Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next);
} }
} }

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IAsyncAuthorizationFilter : IFilterMetadata public interface IAsyncAuthorizationFilter : IFilterMetadata
{ {
Task OnAuthorizationAsync([NotNull] AuthorizationContext context); Task OnAuthorizationAsync(AuthorizationContext context);
} }
} }

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IAsyncExceptionFilter : IFilterMetadata public interface IAsyncExceptionFilter : IFilterMetadata
{ {
Task OnExceptionAsync([NotNull] ExceptionContext context); Task OnExceptionAsync(ExceptionContext context);
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.Filters
/// A <see cref="Task"/> which will complete when the remainder of the pipeline completes. /// A <see cref="Task"/> which will complete when the remainder of the pipeline completes.
/// </returns> /// </returns>
Task OnResourceExecutionAsync( Task OnResourceExecutionAsync(
[NotNull] ResourceExecutingContext context, ResourceExecutingContext context,
[NotNull] ResourceExecutionDelegate next); ResourceExecutionDelegate next);
} }
} }

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IAsyncResultFilter : IFilterMetadata public interface IAsyncResultFilter : IFilterMetadata
{ {
Task OnResultExecutionAsync([NotNull] ResultExecutingContext context, [NotNull] ResultExecutionDelegate next); Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next);
} }
} }

View File

@ -1,12 +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. // 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 namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IAuthorizationFilter : IFilterMetadata public interface IAuthorizationFilter : IFilterMetadata
{ {
void OnAuthorization([NotNull] AuthorizationContext context); void OnAuthorization(AuthorizationContext context);
} }
} }

View File

@ -1,12 +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. // 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 namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IExceptionFilter : IFilterMetadata public interface IExceptionFilter : IFilterMetadata
{ {
void OnException([NotNull] ExceptionContext context); void OnException(ExceptionContext context);
} }
} }

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IFilterFactory : IFilterMetadata public interface IFilterFactory : IFilterMetadata
{ {
IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider); IFilterMetadata CreateInstance(IServiceProvider serviceProvider);
} }
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IFilterProvider public interface IFilterProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.Filters
/// </remarks> /// </remarks>
int Order { get; } int Order { get; }
void OnProvidersExecuting([NotNull] FilterProviderContext context); void OnProvidersExecuting(FilterProviderContext context);
void OnProvidersExecuted([NotNull] FilterProviderContext context); void OnProvidersExecuted(FilterProviderContext context);
} }
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.Filters
{ {
/// <summary> /// <summary>
@ -15,12 +13,12 @@ namespace Microsoft.AspNet.Mvc.Filters
/// Executes the resource filter. Called before execution of the remainder of the pipeline. /// Executes the resource filter. Called before execution of the remainder of the pipeline.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ResourceExecutingContext"/>.</param> /// <param name="context">The <see cref="ResourceExecutingContext"/>.</param>
void OnResourceExecuting([NotNull] ResourceExecutingContext context); void OnResourceExecuting(ResourceExecutingContext context);
/// <summary> /// <summary>
/// Executes the resource filter. Called after execution of the remainder of the pipeline. /// Executes the resource filter. Called after execution of the remainder of the pipeline.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ResourceExecutedContext"/>.</param> /// <param name="context">The <see cref="ResourceExecutedContext"/>.</param>
void OnResourceExecuted([NotNull] ResourceExecutedContext context); void OnResourceExecuted(ResourceExecutedContext context);
} }
} }

View File

@ -1,14 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public interface IResultFilter : IFilterMetadata public interface IResultFilter : IFilterMetadata
{ {
void OnResultExecuting([NotNull] ResultExecutingContext context); void OnResultExecuting(ResultExecutingContext context);
void OnResultExecuted([NotNull] ResultExecutedContext context); void OnResultExecuted(ResultExecutedContext context);
} }
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -14,12 +13,17 @@ namespace Microsoft.AspNet.Mvc.Filters
private ExceptionDispatchInfo _exceptionDispatchInfo; private ExceptionDispatchInfo _exceptionDispatchInfo;
public ResultExecutedContext( public ResultExecutedContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters, IList<IFilterMetadata> filters,
[NotNull] IActionResult result, IActionResult result,
object controller) object controller)
: base(actionContext, filters) : base(actionContext, filters)
{ {
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
Result = result; Result = result;
Controller = controller; Controller = controller;
} }

View File

@ -2,16 +2,15 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
public class ResultExecutingContext : FilterContext public class ResultExecutingContext : FilterContext
{ {
public ResultExecutingContext( public ResultExecutingContext(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IList<IFilterMetadata> filters, IList<IFilterMetadata> filters,
[NotNull] IActionResult result, IActionResult result,
object controller) object controller)
: base(actionContext, filters) : base(actionContext, filters)
{ {

View File

@ -4,7 +4,6 @@
using System; using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Formatters namespace Microsoft.AspNet.Mvc.Formatters
{ {
@ -27,11 +26,31 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// The <see cref="Type"/> of the model to deserialize. /// The <see cref="Type"/> of the model to deserialize.
/// </param> /// </param>
public InputFormatterContext( public InputFormatterContext(
[NotNull] HttpContext httpContext, HttpContext httpContext,
[NotNull] string modelName, string modelName,
[NotNull] ModelStateDictionary modelState, ModelStateDictionary modelState,
[NotNull] Type modelType) 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; HttpContext = httpContext;
ModelName = modelName; ModelName = modelName;
ModelState = modelState; ModelState = modelState;

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -96,8 +95,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="isFromRequest"> /// <param name="isFromRequest">
/// A value indicating whether or not the data comes from the HTTP request. /// A value indicating whether or not the data comes from the HTTP request.
/// </param> /// </param>
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; Id = id;
DisplayName = displayName; DisplayName = displayName;
IsGreedy = isGreedy; 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 /// This distinction is important as the left-hand-side may be a composite, but the right
/// may not. /// may not.
/// </remarks> /// </remarks>
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) if (bindingSource is CompositeBindingSource)
{ {
var message = Resources.FormatBindingSource_CannotBeComposite( var message = Resources.FormatBindingSource_CannotBeComposite(

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -24,9 +23,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="displayName">The display name for the composite source.</param> /// <param name="displayName">The display name for the composite source.</param>
/// <returns>A <see cref="CompositeBindingSource"/>.</returns> /// <returns>A <see cref="CompositeBindingSource"/>.</returns>
public static CompositeBindingSource Create( public static CompositeBindingSource Create(
[NotNull] IEnumerable<BindingSource> bindingSources, IEnumerable<BindingSource> bindingSources,
string displayName) string displayName)
{ {
if (bindingSources == null)
{
throw new ArgumentNullException(nameof(bindingSources));
}
foreach (var bindingSource in bindingSources) foreach (var bindingSource in bindingSources)
{ {
if (bindingSource.IsGreedy) if (bindingSource.IsGreedy)
@ -59,11 +63,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
private CompositeBindingSource( private CompositeBindingSource(
[NotNull] string id, string id,
string displayName, string displayName,
[NotNull] IEnumerable<BindingSource> bindingSources) IEnumerable<BindingSource> bindingSources)
: base(id, displayName, isGreedy: false, isFromRequest: true) : 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; BindingSources = bindingSources;
} }
@ -73,8 +87,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public IEnumerable<BindingSource> BindingSources { get; } public IEnumerable<BindingSource> BindingSources { get; }
/// <inheritdoc /> /// <inheritdoc />
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) if (bindingSource is CompositeBindingSource)
{ {
var message = Resources.FormatBindingSource_CannotBeComposite( var message = Resources.FormatBindingSource_CannotBeComposite(

View File

@ -3,15 +3,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public interface IModelMetadataProvider public interface IModelMetadataProvider
{ {
ModelMetadata GetMetadataForType([NotNull] Type modelType); ModelMetadata GetMetadataForType(Type modelType);
IEnumerable<ModelMetadata> GetMetadataForProperties([NotNull] Type modelType); IEnumerable<ModelMetadata> GetMetadataForProperties(Type modelType);
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -15,6 +14,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <returns> /// <returns>
/// A <see cref="Task"/> that when completed will yield a <see cref="IValueProvider"/> instance or <c>null</c>. /// A <see cref="Task"/> that when completed will yield a <see cref="IValueProvider"/> instance or <c>null</c>.
/// </returns> /// </returns>
Task<IValueProvider> GetValueProviderAsync([NotNull] ValueProviderFactoryContext context); Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context);
} }
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
{ {
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
/// </summary> /// </summary>
/// <param name="modelType">The model <see cref="Type"/>.</param> /// <param name="modelType">The model <see cref="Type"/>.</param>
/// <returns>A <see cref="ModelMetadataIdentity"/>.</returns> /// <returns>A <see cref="ModelMetadataIdentity"/>.</returns>
public static ModelMetadataIdentity ForType([NotNull] Type modelType) public static ModelMetadataIdentity ForType(Type modelType)
{ {
if (modelType == null)
{
throw new ArgumentNullException(nameof(modelType));
}
return new ModelMetadataIdentity() return new ModelMetadataIdentity()
{ {
ModelType = modelType, ModelType = modelType,
@ -33,10 +37,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
/// <param name="containerType">The container type of the model property.</param> /// <param name="containerType">The container type of the model property.</param>
/// <returns>A <see cref="ModelMetadataIdentity"/>.</returns> /// <returns>A <see cref="ModelMetadataIdentity"/>.</returns>
public static ModelMetadataIdentity ForProperty( public static ModelMetadataIdentity ForProperty(
[NotNull] Type modelType, Type modelType,
string name, 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)) if (string.IsNullOrEmpty(name))
{ {
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(name)); throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(name));

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -12,6 +11,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
public class ModelBindingContext public class ModelBindingContext
{ {
private string _fieldName;
private ModelMetadata _modelMetadata;
private string _modelName;
private ModelStateDictionary _modelState;
private OperationBindingContext _operationBindingContext;
private IValueProvider _valueProvider;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ModelBindingContext"/> class. /// Initializes a new instance of the <see cref="ModelBindingContext"/> class.
/// </summary> /// </summary>
@ -30,12 +36,32 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="modelName">The name of the property or parameter being bound.</param> /// <param name="modelName">The name of the property or parameter being bound.</param>
/// <returns>A new instance of <see cref="ModelBindingContext"/>.</returns> /// <returns>A new instance of <see cref="ModelBindingContext"/>.</returns>
public static ModelBindingContext CreateBindingContext( public static ModelBindingContext CreateBindingContext(
[NotNull] OperationBindingContext operationBindingContext, OperationBindingContext operationBindingContext,
[NotNull] ModelStateDictionary modelState, ModelStateDictionary modelState,
[NotNull] ModelMetadata metadata, ModelMetadata metadata,
BindingInfo bindingInfo, 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 binderModelName = bindingInfo?.BinderModelName ?? metadata.BinderModelName;
var propertyPredicateProvider = var propertyPredicateProvider =
bindingInfo?.PropertyBindingPredicateProvider ?? metadata.PropertyBindingPredicateProvider; bindingInfo?.PropertyBindingPredicateProvider ?? metadata.PropertyBindingPredicateProvider;
@ -66,12 +92,32 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
public static ModelBindingContext CreateChildBindingContext( public static ModelBindingContext CreateChildBindingContext(
[NotNull] ModelBindingContext parent, ModelBindingContext parent,
[NotNull] ModelMetadata modelMetadata, ModelMetadata modelMetadata,
[NotNull] string fieldName, string fieldName,
[NotNull] string modelName, string modelName,
object model) 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() return new ModelBindingContext()
{ {
ModelState = parent.ModelState, ModelState = parent.ModelState,
@ -93,12 +139,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// Represents the <see cref="OperationBindingContext"/> associated with this context. /// Represents the <see cref="OperationBindingContext"/> associated with this context.
/// </summary> /// </summary>
public OperationBindingContext OperationBindingContext { get; [param:NotNull] set; } public OperationBindingContext OperationBindingContext
{
get { return _operationBindingContext; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_operationBindingContext = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the name of the current field being bound. /// Gets or sets the name of the current field being bound.
/// </summary> /// </summary>
public string FieldName { get; [param: NotNull] set; } public string FieldName
{
get { return _fieldName; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_fieldName = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the model value for the current operation. /// Gets or sets the model value for the current operation.
@ -112,19 +182,55 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// Gets or sets the metadata for the model associated with this context. /// Gets or sets the metadata for the model associated with this context.
/// </summary> /// </summary>
public ModelMetadata ModelMetadata { get; [param: NotNull] set; } public ModelMetadata ModelMetadata
{
get { return _modelMetadata; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_modelMetadata = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the name of the model. This property is used as a key for looking up values in /// Gets or sets the name of the model. This property is used as a key for looking up values in
/// <see cref="IValueProvider"/> during model binding. /// <see cref="IValueProvider"/> during model binding.
/// </summary> /// </summary>
public string ModelName { get; [param: NotNull] set; } public string ModelName
{
get { return _modelName; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_modelName = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the <see cref="ModelStateDictionary"/> used to capture <see cref="ModelState"/> values /// Gets or sets the <see cref="ModelStateDictionary"/> used to capture <see cref="ModelState"/> values
/// for properties in the object graph of the model when binding. /// for properties in the object graph of the model when binding.
/// </summary> /// </summary>
public ModelStateDictionary ModelState { get; [param: NotNull] set; } public ModelStateDictionary ModelState
{
get { return _modelState; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_modelState = value;
}
}
/// <summary> /// <summary>
/// Gets the type of the model. /// Gets the type of the model.
@ -171,7 +277,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// Gets or sets the <see cref="IValueProvider"/> associated with this context. /// Gets or sets the <see cref="IValueProvider"/> associated with this context.
/// </summary> /// </summary>
public IValueProvider ValueProvider { get; [param: NotNull] set; } public IValueProvider ValueProvider
{
get { return _valueProvider; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_valueProvider = value;
}
}
/// <summary> /// <summary>
/// Gets or sets a predicate which will be evaluated for each property to determine if the property /// Gets or sets a predicate which will be evaluated for each property to determine if the property

View File

@ -29,8 +29,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
/// <param name="key">The key of the current model binding operation.</param> /// <param name="key">The key of the current model binding operation.</param>
/// <returns>A <see cref="ModelBindingResult"/> representing a failed model binding operation.</returns> /// <returns>A <see cref="ModelBindingResult"/> representing a failed model binding operation.</returns>
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); return new ModelBindingResult(key, model: null, isModelSet: false);
} }
@ -39,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
/// <param name="key">The key of the current model binding operation.</param> /// <param name="key">The key of the current model binding operation.</param>
/// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a failed model binding operation.</returns> /// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a failed model binding operation.</returns>
public static Task<ModelBindingResult> FailedAsync([NotNull] string key) public static Task<ModelBindingResult> FailedAsync(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return Task.FromResult(Failed(key)); return Task.FromResult(Failed(key));
} }
@ -51,9 +61,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="model">The model value. May be <c>null.</c></param> /// <param name="model">The model value. May be <c>null.</c></param>
/// <returns>A <see cref="ModelBindingResult"/> representing a successful model bind.</returns> /// <returns>A <see cref="ModelBindingResult"/> representing a successful model bind.</returns>
public static ModelBindingResult Success( public static ModelBindingResult Success(
[NotNull] string key, string key,
object model) object model)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return new ModelBindingResult(key, model, isModelSet: true); return new ModelBindingResult(key, model, isModelSet: true);
} }
@ -65,9 +80,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="model">The model value. May be <c>null.</c></param> /// <param name="model">The model value. May be <c>null.</c></param>
/// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a successful model bind.</returns> /// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a successful model bind.</returns>
public static Task<ModelBindingResult> SuccessAsync( public static Task<ModelBindingResult> SuccessAsync(
[NotNull] string key, string key,
object model) object model)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return Task.FromResult(Success(key, model)); return Task.FromResult(Success(key, model));
} }

View File

@ -2,20 +2,28 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public class ModelError public class ModelError
{ {
public ModelError([NotNull]Exception exception) public ModelError(Exception exception)
: this(exception, errorMessage: null) : 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) : this(errorMessage)
{ {
if (exception == null)
{
throw new ArgumentNullException(nameof(exception));
}
Exception = exception; Exception = exception;
} }

View File

@ -3,19 +3,28 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public class ModelErrorCollection : Collection<ModelError> public class ModelErrorCollection : Collection<ModelError>
{ {
public void Add([NotNull]Exception exception) public void Add(Exception exception)
{ {
if (exception == null)
{
throw new ArgumentNullException(nameof(exception));
}
Add(new ModelError(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)); Add(new ModelError(errorMessage));
} }
} }

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// Creates a new <see cref="ModelMetadata"/>. /// Creates a new <see cref="ModelMetadata"/>.
/// </summary> /// </summary>
/// <param name="identity">The <see cref="ModelMetadataIdentity"/>.</param> /// <param name="identity">The <see cref="ModelMetadataIdentity"/>.</param>
protected ModelMetadata([NotNull] ModelMetadataIdentity identity) protected ModelMetadata(ModelMetadataIdentity identity)
{ {
Identity = identity; Identity = identity;
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// Creates a new <see cref="ModelPropertyCollection"/>. /// Creates a new <see cref="ModelPropertyCollection"/>.
/// </summary> /// </summary>
/// <param name="properties">The properties.</param> /// <param name="properties">The properties.</param>
public ModelPropertyCollection([NotNull] IEnumerable<ModelMetadata> properties) public ModelPropertyCollection(IEnumerable<ModelMetadata> properties)
{ {
if (properties == null)
{
throw new ArgumentNullException(nameof(properties));
}
_properties = new List<ModelMetadata>(properties); _properties = new List<ModelMetadata>(properties);
} }
@ -43,11 +47,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// The <see cref="ModelMetadata"/> instance for the property specified by <paramref name="propertyName"/>, or null /// The <see cref="ModelMetadata"/> instance for the property specified by <paramref name="propertyName"/>, or null
/// if no match can be found. /// if no match can be found.
/// </returns> /// </returns>
public ModelMetadata this[[NotNull] string propertyName] public ModelMetadata this[string propertyName]
{ {
get get
{ {
if (propertyName == null)
{
throw new ArgumentNullException(nameof(propertyName));
}
foreach (var property in _properties) foreach (var property in _properties)
{ {
if (string.Equals(property.PropertyName, propertyName, StringComparison.Ordinal)) if (string.Equals(property.PropertyName, propertyName, StringComparison.Ordinal))

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
@ -49,10 +48,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// from the specified <paramref name="dictionary"/>. /// from the specified <paramref name="dictionary"/>.
/// </summary> /// </summary>
/// <param name="dictionary">The <see cref="ModelStateDictionary"/> to copy values from.</param> /// <param name="dictionary">The <see cref="ModelStateDictionary"/> to copy values from.</param>
public ModelStateDictionary([NotNull] ModelStateDictionary dictionary) public ModelStateDictionary(ModelStateDictionary dictionary)
{ {
_innerDictionary = new CopyOnWriteDictionary<string, ModelState>(dictionary, if (dictionary == null)
StringComparer.OrdinalIgnoreCase); {
throw new ArgumentNullException(nameof(dictionary));
}
_innerDictionary = new CopyOnWriteDictionary<string, ModelState>(
dictionary,
StringComparer.OrdinalIgnoreCase);
MaxAllowedErrors = dictionary.MaxAllowedErrors; MaxAllowedErrors = dictionary.MaxAllowedErrors;
ErrorCount = dictionary.ErrorCount; ErrorCount = dictionary.ErrorCount;
@ -152,16 +157,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public ModelState this[[NotNull] string key] public ModelState this[string key]
{ {
get get
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
ModelState value; ModelState value;
_innerDictionary.TryGetValue(key, out value); _innerDictionary.TryGetValue(key, out value);
return value; return value;
} }
set set
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
if (value == null) if (value == null)
{ {
throw new ArgumentNullException(nameof(value)); throw new ArgumentNullException(nameof(value));
@ -185,8 +200,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param>
/// <param name="exception">The <see cref="Exception"/> to add.</param> /// <param name="exception">The <see cref="Exception"/> to add.</param>
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); TryAddModelError(key, exception);
} }
@ -201,8 +226,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <c>True</c> if the given error was added, <c>false</c> if the error was ignored. /// <c>True</c> if the given error was added, <c>false</c> if the error was ignored.
/// See <see cref="MaxAllowedErrors"/>. /// See <see cref="MaxAllowedErrors"/>.
/// </returns> /// </returns>
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) if (ErrorCount >= MaxAllowedErrors - 1)
{ {
EnsureMaxErrorsReachedRecorded(); EnsureMaxErrorsReachedRecorded();
@ -241,8 +276,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param>
/// <param name="errorMessage">The error message to add.</param> /// <param name="errorMessage">The error message to add.</param>
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); TryAddModelError(key, errorMessage);
} }
@ -257,8 +302,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <c>True</c> if the given error was added, <c>false</c> if the error was ignored. /// <c>True</c> if the given error was added, <c>false</c> if the error was ignored.
/// See <see cref="MaxAllowedErrors"/>. /// See <see cref="MaxAllowedErrors"/>.
/// </returns> /// </returns>
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) if (ErrorCount >= MaxAllowedErrors - 1)
{ {
EnsureMaxErrorsReachedRecorded(); EnsureMaxErrorsReachedRecorded();
@ -281,8 +336,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <returns>Returns <see cref="ModelValidationState.Unvalidated"/> if no entries are found for the specified /// <returns>Returns <see cref="ModelValidationState.Unvalidated"/> if no entries are found for the specified
/// key, <see cref="ModelValidationState.Invalid"/> if at least one instance is found with one or more model /// key, <see cref="ModelValidationState.Invalid"/> if at least one instance is found with one or more model
/// state errors; <see cref="ModelValidationState.Valid"/> otherwise.</returns> /// state errors; <see cref="ModelValidationState.Valid"/> otherwise.</returns>
public ModelValidationState GetFieldValidationState([NotNull] string key) public ModelValidationState GetFieldValidationState(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
var entries = FindKeysWithPrefix(key); var entries = FindKeysWithPrefix(key);
if (!entries.Any()) if (!entries.Any())
{ {
@ -299,8 +359,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <returns>Returns <see cref="ModelValidationState.Unvalidated"/> if no entry is found for the specified /// <returns>Returns <see cref="ModelValidationState.Unvalidated"/> if no entry is found for the specified
/// key, <see cref="ModelValidationState.Invalid"/> if an instance is found with one or more model /// key, <see cref="ModelValidationState.Invalid"/> if an instance is found with one or more model
/// state errors; <see cref="ModelValidationState.Valid"/> otherwise.</returns> /// state errors; <see cref="ModelValidationState.Valid"/> otherwise.</returns>
public ModelValidationState GetValidationState([NotNull] string key) public ModelValidationState GetValidationState(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
ModelState validationState; ModelState validationState;
if (TryGetValue(key, out validationState)) if (TryGetValue(key, out validationState))
{ {
@ -315,8 +380,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// as <see cref="ModelValidationState.Valid"/>. /// as <see cref="ModelValidationState.Valid"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to mark as valid.</param> /// <param name="key">The key of the <see cref="ModelState"/> to mark as valid.</param>
public void MarkFieldValid([NotNull] string key) public void MarkFieldValid(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
var modelState = GetModelStateForKey(key); var modelState = GetModelStateForKey(key);
if (modelState.ValidationState == ModelValidationState.Invalid) if (modelState.ValidationState == ModelValidationState.Invalid)
{ {
@ -331,8 +401,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// as <see cref="ModelValidationState.Skipped"/>. /// as <see cref="ModelValidationState.Skipped"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to mark as skipped.</param> /// <param name="key">The key of the <see cref="ModelState"/> to mark as skipped.</param>
public void MarkFieldSkipped([NotNull] string key) public void MarkFieldSkipped(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
var modelState = GetModelStateForKey(key); var modelState = GetModelStateForKey(key);
if (modelState.ValidationState == ModelValidationState.Invalid) if (modelState.ValidationState == ModelValidationState.Invalid)
{ {
@ -369,8 +444,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="attemptedValue"> /// <param name="attemptedValue">
/// The values of <param name="rawValue"/> in a comma-separated <see cref="string"/>. /// The values of <param name="rawValue"/> in a comma-separated <see cref="string"/>.
/// </param> /// </param>
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); var modelState = GetModelStateForKey(key);
modelState.RawValue = rawValue; modelState.RawValue = rawValue;
modelState.AttemptedValue = attemptedValue; modelState.AttemptedValue = attemptedValue;
@ -383,8 +463,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="valueProviderResult"> /// <param name="valueProviderResult">
/// A <see cref="ValueProviderResult"/> with data for the <see cref="ModelState"/> entry. /// A <see cref="ValueProviderResult"/> with data for the <see cref="ModelState"/> entry.
/// </param> /// </param>
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. // Avoid creating a new array for rawValue if there's only one value.
object rawValue; object rawValue;
if (valueProviderResult == ValueProviderResult.None) 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 // If key is null or empty, clear all entries in the dictionary
// else just clear the ones that have key as prefix // else just clear the ones that have key as prefix
var entries = (string.IsNullOrEmpty(key)) ? var entries = (string.IsNullOrEmpty(key)) ?
_innerDictionary : FindKeysWithPrefix(key); _innerDictionary : FindKeysWithPrefix(key);
foreach (var entry in entries) 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; ModelState modelState;
if (!TryGetValue(key, out modelState)) if (!TryGetValue(key, out modelState))
{ {
@ -477,8 +567,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
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); _innerDictionary.Add(key, value);
} }
@ -495,14 +595,24 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public bool ContainsKey([NotNull] string key) public bool ContainsKey(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _innerDictionary.ContainsKey(key); return _innerDictionary.ContainsKey(key);
} }
/// <inheritdoc /> /// <inheritdoc />
public void CopyTo([NotNull] KeyValuePair<string, ModelState>[] array, int arrayIndex) public void CopyTo(KeyValuePair<string, ModelState>[] array, int arrayIndex)
{ {
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
_innerDictionary.CopyTo(array, arrayIndex); _innerDictionary.CopyTo(array, arrayIndex);
} }
@ -513,14 +623,24 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Remove([NotNull] string key) public bool Remove(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _innerDictionary.Remove(key); return _innerDictionary.Remove(key);
} }
/// <inheritdoc /> /// <inheritdoc />
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); return _innerDictionary.TryGetValue(key, out value);
} }
@ -536,8 +656,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return GetEnumerator(); return GetEnumerator();
} }
public IEnumerable<KeyValuePair<string, ModelState>> FindKeysWithPrefix([NotNull] string prefix) public IEnumerable<KeyValuePair<string, ModelState>> FindKeysWithPrefix(string prefix)
{ {
if (prefix == null)
{
throw new ArgumentNullException(nameof(prefix));
}
ModelState exactMatchValue; ModelState exactMatchValue;
if (_innerDictionary.TryGetValue(prefix, out exactMatchValue)) if (_innerDictionary.TryGetValue(prefix, out exactMatchValue))
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -16,9 +15,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// exception <paramref name="message"/>. /// exception <paramref name="message"/>.
/// </summary> /// </summary>
/// <param name="message">The message that describes the error.</param> /// <param name="message">The message that describes the error.</param>
public TooManyModelErrorsException([NotNull] string message) public TooManyModelErrorsException(string message)
: base(message) : base(message)
{ {
if (message == null)
{
throw new ArgumentNullException(nameof(message));
}
} }
} }
} }

View File

@ -2,17 +2,31 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{ {
public class ClientModelValidationContext public class ClientModelValidationContext
{ {
public ClientModelValidationContext( public ClientModelValidationContext(
[NotNull] ModelMetadata metadata, ModelMetadata metadata,
[NotNull] IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
[NotNull] IServiceProvider requestServices) 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; ModelMetadata = metadata;
MetadataProvider = metadataProvider; MetadataProvider = metadataProvider;
RequestServices = requestServices; RequestServices = requestServices;

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{ {
public interface IClientModelValidator public interface IClientModelValidator
{ {
IEnumerable<ModelClientValidationRule> GetClientValidationRules([NotNull] ClientModelValidationContext context); IEnumerable<ModelClientValidationRule> GetClientValidationRules(ClientModelValidationContext context);
} }
} }

View File

@ -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. // 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 namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{ {
/// <summary> /// <summary>
@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
/// by updating <see cref="ClientValidatorProviderContext.Validators"/>. /// by updating <see cref="ClientValidatorProviderContext.Validators"/>.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ClientModelValidationContext"/> associated with this call.</param> /// <param name="context">The <see cref="ClientModelValidationContext"/> associated with this call.</param>
void GetValidators([NotNull] ClientValidatorProviderContext context); void GetValidators(ClientValidatorProviderContext context);
} }
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{ {
@ -12,15 +11,29 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
private readonly Dictionary<string, object> _validationParameters = private readonly Dictionary<string, object> _validationParameters =
new Dictionary<string, object>(StringComparer.Ordinal); new Dictionary<string, object>(StringComparer.Ordinal);
public ModelClientValidationRule([NotNull] string errorMessage) public ModelClientValidationRule(string errorMessage)
: this(validationType: string.Empty, errorMessage: errorMessage) : this(validationType: string.Empty, errorMessage: errorMessage)
{ {
if (errorMessage == null)
{
throw new ArgumentNullException(nameof(errorMessage));
}
} }
public ModelClientValidationRule( public ModelClientValidationRule(
[NotNull] string validationType, string validationType,
[NotNull] string errorMessage) string errorMessage)
{ {
if (validationType == null)
{
throw new ArgumentNullException(nameof(validationType));
}
if (errorMessage == null)
{
throw new ArgumentNullException(nameof(errorMessage));
}
ValidationType = validationType; ValidationType = validationType;
ErrorMessage = errorMessage; ErrorMessage = errorMessage;
} }

View File

@ -1,18 +1,28 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public class ValueProviderFactoryContext public class ValueProviderFactoryContext
{ {
public ValueProviderFactoryContext( public ValueProviderFactoryContext(
[NotNull] HttpContext httpContext, HttpContext httpContext,
[NotNull] IDictionary<string, object> routeValues) IDictionary<string, object> routeValues)
{ {
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
if (routeValues == null)
{
throw new ArgumentNullException(nameof(routeValues));
}
HttpContext = httpContext; HttpContext = httpContext;
RouteValues = routeValues; RouteValues = routeValues;
} }

View File

@ -22,10 +22,6 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"type": "build" "type": "build"
}, },
"Microsoft.Framework.NotNullAttribute.Sources": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.Framework.PropertyHelper.Sources": { "Microsoft.Framework.PropertyHelper.Sources": {
"version": "1.0.0-*", "version": "1.0.0-*",
"type": "build" "type": "build"

View File

@ -4,19 +4,28 @@
using System; using System;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
public static class MvcServiceCollectionExtensions 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); return AddMvc(services, setupAction: null);
} }
public static IMvcBuilder AddMvc([NotNull] this IServiceCollection services, Action<MvcOptions> setupAction) public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOptions> setupAction)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
var builder = services.AddMvcCore(); var builder = services.AddMvcCore();
builder.AddApiExplorer(); builder.AddApiExplorer();

View File

@ -210,6 +210,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
var actionBindingContext = new ActionBindingContext() var actionBindingContext = new ActionBindingContext()
{ {
ModelBinder = binder.Object, ModelBinder = binder.Object,
ValueProvider = new SimpleValueProvider(),
}; };
var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict); var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict);
@ -305,6 +306,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
var actionBindingContext = new ActionBindingContext() var actionBindingContext = new ActionBindingContext()
{ {
ModelBinder = binder.Object, ModelBinder = binder.Object,
ValueProvider = new SimpleValueProvider(),
}; };
var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict); var mockValidator = new Mock<IObjectModelValidator>(MockBehavior.Strict);
@ -413,6 +415,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
var actionBindingContext = new ActionBindingContext() var actionBindingContext = new ActionBindingContext()
{ {
ModelBinder = binder.Object, ModelBinder = binder.Object,
ValueProvider = new SimpleValueProvider(),
}; };
var argumentBinder = GetArgumentBinder(); var argumentBinder = GetArgumentBinder();
@ -451,6 +454,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
var actionBindingContext = new ActionBindingContext() var actionBindingContext = new ActionBindingContext()
{ {
ModelBinder = binder.Object, ModelBinder = binder.Object,
ValueProvider = new SimpleValueProvider(),
}; };
var argumentBinder = GetArgumentBinder(); var argumentBinder = GetArgumentBinder();
@ -600,6 +604,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
var actionBindingContext = new ActionBindingContext var actionBindingContext = new ActionBindingContext
{ {
ModelBinder = binder.Object, ModelBinder = binder.Object,
ValueProvider = new SimpleValueProvider(),
}; };
// Act // Act

View File

@ -379,6 +379,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
OperationBindingContext = new OperationBindingContext(), OperationBindingContext = new OperationBindingContext(),
ValueProvider = new SimpleValueProvider(), ValueProvider = new SimpleValueProvider(),
FieldName = "test-field",
}; };
// Act // Act
@ -528,6 +529,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
IsTopLevelObject = true, IsTopLevelObject = true,
ModelMetadata = metadataProvider.GetMetadataForType(type), ModelMetadata = metadataProvider.GetMetadataForType(type),
ModelName = "parameter", ModelName = "parameter",
FieldName = "parameter",
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
ValueProvider = valueProvider, ValueProvider = valueProvider,
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext

View File

@ -278,7 +278,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),
}, },
// Setting it to empty ensures that model does not get created becasue of no model name. // 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. // Setting it to empty ensures that model does not get created becasue of no model name.
ModelName = "dummyName", ModelName = "dummyName",
BindingSource = modelMetadata.BindingSource, BindingSource = modelMetadata.BindingSource,
BinderModelName = modelMetadata.BinderModelName BinderModelName = modelMetadata.BinderModelName,
ModelState = new ModelStateDictionary(),
} }
}; };
@ -384,7 +386,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),
}, },
// Setting it to empty ensures that model does not get created becasue of no model name. // 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, ModelBinder = mockBinder.Object,
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),
ValidatorProvider = Mock.Of<IModelValidatorProvider>() ValidatorProvider = Mock.Of<IModelValidatorProvider>()
} },
ModelState = new ModelStateDictionary(),
}; };
var model = new Person(); var model = new Person();
@ -475,7 +479,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelBinder = mockBinder.Object, ModelBinder = mockBinder.Object,
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),
ValidatorProvider = Mock.Of<IModelValidatorProvider>() ValidatorProvider = Mock.Of<IModelValidatorProvider>()
} },
ModelState = new ModelStateDictionary(),
}; };
var model = new Person(); var model = new Person();

View File

@ -293,7 +293,8 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
{ {
BinderModelName = "CustomParameter", BinderModelName = "CustomParameter",
}, },
ParameterType = typeof(Person2) ParameterType = typeof(Person2),
Name = "param-name",
}; };
var operationContext = ModelBindingTestHelper.GetOperationBindingContext( var operationContext = ModelBindingTestHelper.GetOperationBindingContext(
@ -352,7 +353,8 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
{ {
BinderModelName = "CustomParameter", BinderModelName = "CustomParameter",
}, },
ParameterType = typeof(Person3) ParameterType = typeof(Person3),
Name = "param-name",
}; };
var operationContext = ModelBindingTestHelper.GetOperationBindingContext( var operationContext = ModelBindingTestHelper.GetOperationBindingContext(