Replacing NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-09-30 21:04:56 -07:00
parent 02c36a1c48
commit 3a876e387f
184 changed files with 2739 additions and 803 deletions

View File

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

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer
{
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// </summary>
/// <param name="items">The list of <see cref="ApiDescriptionGroup"/>.</param>
/// <param name="version">The unique version of discovered groups.</param>
public ApiDescriptionGroupCollection([NotNull] IReadOnlyList<ApiDescriptionGroup> items, int version)
public ApiDescriptionGroupCollection(IReadOnlyList<ApiDescriptionGroup> items, int version)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = items;
Version = version;
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer
{
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// Creates a new instance of <see cref="ApiDescriptionProviderContext"/>.
/// </summary>
/// <param name="actions">The list of actions.</param>
public ApiDescriptionProviderContext([NotNull] IReadOnlyList<ActionDescriptor> actions)
public ApiDescriptionProviderContext(IReadOnlyList<ActionDescriptor> actions)
{
if (actions == null)
{
throw new ArgumentNullException(nameof(actions));
}
Actions = actions;
Results = new List<ApiDescription>();

View File

@ -53,8 +53,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
}
/// <inheritdoc />
public void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context)
public void OnProvidersExecuting(ApiDescriptionProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var action in context.Actions.OfType<ControllerActionDescriptor>())
{
var extensionData = action.GetProperty<ApiDescriptionActionData>();
@ -69,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
}
}
public void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context)
public void OnProvidersExecuted(ApiDescriptionProviderContext context)
{
}

View File

@ -1,16 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
public static class MvcApiExplorerMvcCoreBuilderExtensions
{
public static IMvcCoreBuilder AddApiExplorer([NotNull] this IMvcCoreBuilder builder)
public static IMvcCoreBuilder AddApiExplorer(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
AddApiExplorerServices(builder.Services);
return builder;
}

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer
{
public interface IApiDescriptionProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// </remarks>
int Order { get; }
void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context);
void OnProvidersExecuting(ApiDescriptionProviderContext context);
void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context);
void OnProvidersExecuted(ApiDescriptionProviderContext context);
}
}

View File

@ -11,8 +11,7 @@
"dependencies": {
"Microsoft.AspNet.Mvc.Core": "6.0.0-*",
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" }
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" }
},
"frameworks": {
"dnx451": { },

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -22,9 +21,13 @@ namespace Microsoft.AspNet.Mvc
/// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class.
/// </summary>
/// <param name="method">The HTTP method the action supports.</param>
public AcceptVerbsAttribute([NotNull] string method)
public AcceptVerbsAttribute(string method)
: this(new string[] { method })
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
}
/// <summary>

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ActionConstraints
{
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
}
/// <inheritdoc />
public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context)
public void OnProvidersExecuting(ActionConstraintProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var item in context.Results)
{
ProvideConstraint(item, context.HttpContext.RequestServices);
@ -32,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
}
/// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context)
public void OnProvidersExecuted(ActionConstraintProviderContext context)
{
}

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ActionConstraints
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
private readonly string PreflightHttpMethod = "OPTIONS";
// Empty collection means any method will be accepted.
public HttpMethodConstraint([NotNull] IEnumerable<string> httpMethods)
public HttpMethodConstraint(IEnumerable<string> httpMethods)
{
if (httpMethods == null)
{
throw new ArgumentNullException(nameof(httpMethods));
}
var methods = new List<string>();
foreach (var method in httpMethods)
@ -51,8 +55,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
get { return HttpMethodConstraintOrder; }
}
public bool Accept([NotNull] ActionConstraintContext context)
public bool Accept(ActionConstraintContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (_methods.Count == 0)
{
return true;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -8,7 +9,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ActionModel : ICommonModel, IFilterModel, IApiExplorerModel
{
public ActionModel(
[NotNull] MethodInfo actionMethod,
[NotNull] IReadOnlyList<object> attributes)
MethodInfo actionMethod,
IReadOnlyList<object> attributes)
{
if (actionMethod == null)
{
throw new ArgumentNullException(nameof(actionMethod));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ActionMethod = actionMethod;
ApiExplorer = new ApiExplorerModel();
@ -32,8 +42,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
Properties = new Dictionary<object, object>();
}
public ActionModel([NotNull] ActionModel other)
public ActionModel(ActionModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
ActionMethod = other.ActionMethod;
ActionName = other.ActionName;

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Creates a new <see cref="ApiExplorerModel"/> with properties copied from <paramref name="other"/>.
/// </summary>
/// <param name="other">The <see cref="ApiExplorerModel"/> to copy.</param>
public ApiExplorerModel([NotNull] ApiExplorerModel other)
public ApiExplorerModel(ApiExplorerModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
GroupName = other.GroupName;
IsVisible = other.IsVisible;
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -18,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <param name="applicationModel">The <see cref="ApplicationModel"/>.</param>
/// <param name="conventions">The set of conventions.</param>
public static void ApplyConventions(
[NotNull] ApplicationModel applicationModel,
[NotNull] IEnumerable<IApplicationModelConvention> conventions)
ApplicationModel applicationModel,
IEnumerable<IApplicationModelConvention> conventions)
{
if (applicationModel == null)
{
throw new ArgumentNullException(nameof(applicationModel));
}
if (conventions == null)
{
throw new ArgumentNullException(nameof(conventions));
}
// Conventions are applied from the outside-in to allow for scenarios where an action overrides
// a controller, etc.
foreach (var convention in conventions)

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.
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -12,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary>
public class ApplicationModelProviderContext
{
public ApplicationModelProviderContext([NotNull] IEnumerable<TypeInfo> controllerTypes)
public ApplicationModelProviderContext(IEnumerable<TypeInfo> controllerTypes)
{
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllerTypes = controllerTypes;
}

View File

@ -7,7 +7,6 @@ using System.Linq;
using System.Text;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -19,16 +18,26 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
{
}
public AttributeRouteModel([NotNull] IRouteTemplateProvider templateProvider)
public AttributeRouteModel(IRouteTemplateProvider templateProvider)
{
if (templateProvider == null)
{
throw new ArgumentNullException(nameof(templateProvider));
}
Attribute = templateProvider;
Template = templateProvider.Template;
Order = templateProvider.Order;
Name = templateProvider.Name;
}
public AttributeRouteModel([NotNull] AttributeRouteModel other)
public AttributeRouteModel(AttributeRouteModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Attribute = other.Attribute;
Name = other.Name;
Order = other.Order;

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.
using System;
using System.Linq;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.ApplicationModels
@ -18,15 +18,20 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
_authorizationOptions = authorizationOptionsAccessor.Value;
}
public int Order { get { return -1000 + 10; } }
public int Order { get { return -1000 + 10; } }
public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context)
public void OnProvidersExecuted(ApplicationModelProviderContext context)
{
// Intentionally empty.
}
public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context)
public void OnProvidersExecuting(ApplicationModelProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
AuthorizationPolicy policy;
foreach (var controllerModel in context.Result.Controllers)

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -8,7 +9,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ControllerModel : ICommonModel, IFilterModel, IApiExplorerModel
{
public ControllerModel(
[NotNull] TypeInfo controllerType,
[NotNull] IReadOnlyList<object> attributes)
TypeInfo controllerType,
IReadOnlyList<object> attributes)
{
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ControllerType = controllerType;
Actions = new List<ActionModel>();
@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
ControllerProperties = new List<PropertyModel>();
}
public ControllerModel([NotNull] ControllerModel other)
public ControllerModel(ControllerModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
ControllerName = other.ControllerName;
ControllerType = other.ControllerType;

View File

@ -1,17 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
@ -36,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
}
/// <inheritdoc />
public virtual void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context)
public virtual void OnProvidersExecuting(ApplicationModelProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var filter in _globalFilters)
{
context.Result.Filters.Add(filter);
@ -92,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
}
/// <inheritdoc />
public virtual void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context)
public virtual void OnProvidersExecuted(ApplicationModelProviderContext context)
{
// Intentionally empty.
}
@ -105,8 +108,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// A set of <see cref="ControllerModel"/> instances for the given controller <see cref="TypeInfo"/> or
/// <c>null</c> if the <paramref name="typeInfo"/> does not represent a controller.
/// </returns>
protected virtual IEnumerable<ControllerModel> BuildControllerModels([NotNull] TypeInfo typeInfo)
protected virtual IEnumerable<ControllerModel> BuildControllerModels(TypeInfo typeInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
var controllerModel = CreateControllerModel(typeInfo);
yield return controllerModel;
}
@ -116,8 +124,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary>
/// <param name="typeInfo">The <see cref="TypeInfo"/>.</param>
/// <returns>A <see cref="ControllerModel"/> for the given <see cref="TypeInfo"/>.</returns>
protected virtual ControllerModel CreateControllerModel([NotNull] TypeInfo typeInfo)
protected virtual ControllerModel CreateControllerModel(TypeInfo typeInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
// For attribute routes on a controller, we want want to support 'overriding' routes on a derived
// class. So we need to walk up the hierarchy looking for the first class to define routes.
//
@ -214,8 +227,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary>
/// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param>
/// <returns>A <see cref="PropertyModel"/> for the given <see cref="PropertyInfo"/>.</returns>
protected virtual PropertyModel CreatePropertyModel([NotNull] PropertyInfo propertyInfo)
protected virtual PropertyModel CreatePropertyModel(PropertyInfo propertyInfo)
{
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
// CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object>
// is needed to so that the result of ToArray() is object
var attributes = propertyInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray();
@ -239,9 +257,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <c>null</c> if the <paramref name="methodInfo"/> does not represent an action.
/// </returns>
protected virtual IEnumerable<ActionModel> BuildActionModels(
[NotNull] TypeInfo typeInfo,
[NotNull] MethodInfo methodInfo)
TypeInfo typeInfo,
MethodInfo methodInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
if (!IsAction(typeInfo, methodInfo))
{
return Enumerable.Empty<ActionModel>();
@ -436,8 +464,18 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <remarks>
/// Override this method to provide custom logic to determine which methods are considered actions.
/// </remarks>
protected virtual bool IsAction([NotNull] TypeInfo typeInfo, [NotNull] MethodInfo methodInfo)
protected virtual bool IsAction(TypeInfo typeInfo, MethodInfo methodInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
// The SpecialName bit is set to flag members that are treated in a special way by some compilers
// (such as property accessors and operator overloading methods).
if (methodInfo.IsSpecialName)
@ -500,9 +538,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// the action being created.
/// </remarks>
protected virtual ActionModel CreateActionModel(
[NotNull] MethodInfo methodInfo,
[NotNull] IReadOnlyList<object> attributes)
MethodInfo methodInfo,
IReadOnlyList<object> attributes)
{
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
var actionModel = new ActionModel(methodInfo, attributes);
AddRange(actionModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>());
@ -558,8 +606,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary>
/// <param name="parameterInfo">The <see cref="ParameterInfo"/>.</param>
/// <returns>A <see cref="ParameterModel"/> for the given <see cref="ParameterInfo"/>.</returns>
protected virtual ParameterModel CreateParameterModel([NotNull] ParameterInfo parameterInfo)
protected virtual ParameterModel CreateParameterModel(ParameterInfo parameterInfo)
{
if (parameterInfo == null)
{
throw new ArgumentNullException(nameof(parameterInfo));
}
// CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object>
// is needed to so that the result of ToArray() is object
var attributes = parameterInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray();

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
/// <summary>
@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ActionModel"/>.
/// </summary>
/// <param name="action">The <see cref="ActionModel"/>.</param>
void Apply([NotNull] ActionModel action);
void Apply(ActionModel action);
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
/// <summary>
@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ApplicationModel"/>.
/// </summary>
/// <param name="application">The <see cref="ApplicationModel"/>.</param>
void Apply([NotNull] ApplicationModel application);
void Apply(ApplicationModel application);
}
}

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.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
/// <summary>
@ -35,12 +33,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Executed for the first pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param>
void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context);
void OnProvidersExecuting(ApplicationModelProviderContext context);
/// <summary>
/// Executed for the second pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary>
/// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param>
void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context);
void OnProvidersExecuted(ApplicationModelProviderContext context);
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
/// <summary>
@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ControllerModel"/>.
/// </summary>
/// <param name="controller">The <see cref="ControllerModel"/>.</param>
void Apply([NotNull] ControllerModel controller);
void Apply(ControllerModel controller);
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
/// <summary>
@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ParameterModel"/>.
/// </summary>
/// <param name="parameter">The <see cref="ParameterModel"/>.</param>
void Apply([NotNull] ParameterModel parameter);
void Apply(ParameterModel parameter);
}
}

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -13,16 +13,31 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ParameterModel : ICommonModel, IBindingModel
{
public ParameterModel(
[NotNull] ParameterInfo parameterInfo,
[NotNull] IReadOnlyList<object> attributes)
ParameterInfo parameterInfo,
IReadOnlyList<object> attributes)
{
if (parameterInfo == null)
{
throw new ArgumentNullException(nameof(parameterInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ParameterInfo = parameterInfo;
Properties = new Dictionary<object, object>();
Attributes = new List<object>(attributes);
}
public ParameterModel([NotNull] ParameterModel other)
public ParameterModel(ParameterModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Action = other.Action;
Attributes = new List<object>(other.Attributes);
BindingInfo = other.BindingInfo == null ? null : new BindingInfo(other.BindingInfo);

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels
{
@ -21,9 +21,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <param name="propertyInfo">The <see cref="PropertyInfo"/> for the underlying property.</param>
/// <param name="attributes">Any attributes which are annotated on the property.</param>
public PropertyModel(
[NotNull] PropertyInfo propertyInfo,
[NotNull] IReadOnlyList<object> attributes)
PropertyInfo propertyInfo,
IReadOnlyList<object> attributes)
{
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
PropertyInfo = propertyInfo;
Properties = new Dictionary<object, object>();
Attributes = new List<object>(attributes);
@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Creats a new instance of <see cref="PropertyModel"/> from a given <see cref="PropertyModel"/>.
/// </summary>
/// <param name="other">The <see cref="PropertyModel"/> which needs to be copied.</param>
public PropertyModel([NotNull] PropertyModel other)
public PropertyModel(PropertyModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Controller = other.Controller;
Attributes = new List<object>(other.Attributes);
BindingInfo = BindingInfo == null ? null : new BindingInfo(other.BindingInfo);

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,14 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="BadRequestObjectResult"/> instance.
/// </summary>
/// <param name="modelState"><see cref="ModelStateDictionary"/> containing the validation errors.</param>
public BadRequestObjectResult([NotNull] ModelStateDictionary modelState)
public BadRequestObjectResult(ModelStateDictionary modelState)
: base(new SerializableError(modelState))
{
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
StatusCode = StatusCodes.Status400BadRequest;
}
}

View File

@ -8,7 +8,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -46,8 +45,13 @@ namespace Microsoft.AspNet.Mvc
/// <param name="predicateProviderType">The type which implements
/// <see cref="IPropertyBindingPredicateProvider"/>.
/// </param>
public BindAttribute([NotNull] Type predicateProviderType)
public BindAttribute(Type predicateProviderType)
{
if (predicateProviderType == null)
{
throw new ArgumentNullException(nameof(predicateProviderType));
}
if (!typeof(IPropertyBindingPredicateProvider).GetTypeInfo()
.IsAssignableFrom(predicateProviderType.GetTypeInfo()))
{

View File

@ -6,7 +6,6 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Builder
{
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Builder
/// <returns>The <paramref name="app"/>.</returns>
/// <remarks>This method only supports attribute routing. To add conventional routes use
/// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks>
public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app)
public static IApplicationBuilder UseMvc(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMvc(routes =>
{
});
@ -36,8 +40,13 @@ namespace Microsoft.AspNet.Builder
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvcWithDefaultRoute([NotNull] this IApplicationBuilder app)
public static IApplicationBuilder UseMvcWithDefaultRoute(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMvc(routes =>
{
routes.MapRoute(
@ -53,9 +62,19 @@ namespace Microsoft.AspNet.Builder
/// <param name="configureRoutes">A callback to configure MVC routes.</param>
/// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvc(
[NotNull] this IApplicationBuilder app,
[NotNull] Action<IRouteBuilder> configureRoutes)
this IApplicationBuilder app,
Action<IRouteBuilder> configureRoutes)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (configureRoutes == null)
{
throw new ArgumentNullException(nameof(configureRoutes));
}
// Verify if AddMvc was done before calling UseMvc
// We use the MvcMarkerService to make sure if all the services were added.
MvcServicesHelper.ThrowIfMvcNotRegistered(app.ApplicationServices);

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Authentication;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -45,8 +45,13 @@ namespace Microsoft.AspNet.Mvc
public AuthenticationProperties Properties { get; set; }
public override async Task ExecuteResultAsync([NotNull] ActionContext context)
public override async Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var auth = context.HttpContext.Authentication;
if (AuthenticationSchemes.Count > 0)
{

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -24,8 +23,13 @@ namespace Microsoft.AspNet.Mvc
/// <summary>
/// Creates a new instance of <see cref="ConsumesAttribute"/>.
/// </summary>
public ConsumesAttribute([NotNull] string contentType, params string[] otherContentTypes)
public ConsumesAttribute(string contentType, params string[] otherContentTypes)
{
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ContentTypes = GetContentTypes(contentType, otherContentTypes);
}
@ -38,8 +42,13 @@ namespace Microsoft.AspNet.Mvc
public IList<MediaTypeHeaderValue> ContentTypes { get; set; }
/// <inheritdoc />
public void OnResourceExecuting([NotNull] ResourceExecutingContext context)
public void OnResourceExecuting(ResourceExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Only execute if the current filter is the one which is closest to the action.
// Ignore all other filters. This is to ensure we have a overriding behavior.
if (IsApplicable(context.ActionDescriptor))
@ -58,8 +67,12 @@ namespace Microsoft.AspNet.Mvc
}
/// <inheritdoc />
public void OnResourceExecuted([NotNull] ResourceExecutedContext context)
public void OnResourceExecuted(ResourceExecutedContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
public bool Accept(ActionConstraintContext context)

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -33,8 +33,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
public int? StatusCode { get; set; }
public override Task ExecuteResultAsync([NotNull] ActionContext context)
public override Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var response = context.HttpContext.Response;
var contentTypeHeader = ContentType;

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.Controllers
@ -17,10 +17,25 @@ namespace Microsoft.AspNet.Mvc.Controllers
private readonly IEnumerable<IApplicationModelConvention> _conventions;
public ControllerActionDescriptorProvider(
[NotNull] IControllerTypeProvider controllerTypeProvider,
[NotNull] IEnumerable<IApplicationModelProvider> applicationModelProviders,
[NotNull] IOptions<MvcOptions> optionsAccessor)
IControllerTypeProvider controllerTypeProvider,
IEnumerable<IApplicationModelProvider> applicationModelProviders,
IOptions<MvcOptions> optionsAccessor)
{
if (controllerTypeProvider == null)
{
throw new ArgumentNullException(nameof(controllerTypeProvider));
}
if (applicationModelProviders == null)
{
throw new ArgumentNullException(nameof(applicationModelProviders));
}
if (optionsAccessor == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}
_controllerTypeProvider = controllerTypeProvider;
_applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray();
_conventions = optionsAccessor.Value.Conventions;
@ -32,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
/// <inheritdoc />
public void OnProvidersExecuting ([NotNull] ActionDescriptorProviderContext context)
public void OnProvidersExecuting(ActionDescriptorProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var descriptor in GetDescriptors())
{
context.Results.Add(descriptor);
@ -41,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
/// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context)
public void OnProvidersExecuted(ActionDescriptorProviderContext context)
{
}
@ -62,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
_applicationModelProviders[i].OnProvidersExecuting(context);
}
for (var i = _applicationModelProviders.Length - 1 ; i >= 0; i--)
for (var i = _applicationModelProviders.Length - 1; i >= 0; i--)
{
_applicationModelProviders[i].OnProvidersExecuted(context);
}

View File

@ -25,19 +25,19 @@ namespace Microsoft.AspNet.Mvc.Controllers
private readonly IControllerActionArgumentBinder _argumentBinder;
public ControllerActionInvoker(
[NotNull] ActionContext actionContext,
[NotNull] IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IControllerFactory controllerFactory,
[NotNull] ControllerActionDescriptor descriptor,
[NotNull] IReadOnlyList<IInputFormatter> inputFormatters,
[NotNull] IReadOnlyList<IOutputFormatter> outputFormatters,
[NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder,
[NotNull] IReadOnlyList<IModelBinder> modelBinders,
[NotNull] IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
[NotNull] IReadOnlyList<IValueProviderFactory> valueProviderFactories,
[NotNull] IActionBindingContextAccessor actionBindingContextAccessor,
[NotNull] ILogger logger,
[NotNull] TelemetrySource telemetry,
ActionContext actionContext,
IReadOnlyList<IFilterProvider> filterProviders,
IControllerFactory controllerFactory,
ControllerActionDescriptor descriptor,
IReadOnlyList<IInputFormatter> inputFormatters,
IReadOnlyList<IOutputFormatter> outputFormatters,
IControllerActionArgumentBinder controllerActionArgumentBinder,
IReadOnlyList<IModelBinder> modelBinders,
IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
IReadOnlyList<IValueProviderFactory> valueProviderFactories,
IActionBindingContextAccessor actionBindingContextAccessor,
ILogger logger,
TelemetrySource telemetry,
int maxModelValidationErrors)
: base(
actionContext,
@ -52,6 +52,71 @@ namespace Microsoft.AspNet.Mvc.Controllers
telemetry,
maxModelValidationErrors)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (filterProviders == null)
{
throw new ArgumentNullException(nameof(filterProviders));
}
if (controllerFactory == null)
{
throw new ArgumentNullException(nameof(controllerFactory));
}
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (inputFormatters == null)
{
throw new ArgumentNullException(nameof(inputFormatters));
}
if (outputFormatters == null)
{
throw new ArgumentNullException(nameof(outputFormatters));
}
if (controllerActionArgumentBinder == null)
{
throw new ArgumentNullException(nameof(controllerActionArgumentBinder));
}
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
if (modelValidatorProviders == null)
{
throw new ArgumentNullException(nameof(modelValidatorProviders));
}
if (valueProviderFactories == null)
{
throw new ArgumentNullException(nameof(valueProviderFactories));
}
if (actionBindingContextAccessor == null)
{
throw new ArgumentNullException(nameof(actionBindingContextAccessor));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}
_descriptor = descriptor;
_controllerFactory = controllerFactory;
_argumentBinder = controllerActionArgumentBinder;
@ -95,12 +160,27 @@ namespace Microsoft.AspNet.Mvc.Controllers
ActionContext context,
ActionBindingContext bindingContext)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
return _argumentBinder.BindActionArgumentsAsync(context, bindingContext, Instance);
}
// Marking as internal for Unit Testing purposes.
internal static IActionResult CreateActionResult([NotNull] Type declaredReturnType, object actionReturnValue)
internal static IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue)
{
if (declaredReturnType == null)
{
throw new ArgumentNullException(nameof(declaredReturnType));
}
// optimize common path
var actionResult = actionReturnValue as IActionResult;
if (actionResult != null)

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
@ -10,7 +11,6 @@ using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
@ -60,32 +60,37 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
/// <inheritdoc />
public void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context)
public void OnProvidersExecuting(ActionInvokerProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor != null)
{
context.Result = new ControllerActionInvoker(
context.ActionContext,
_filterProviders,
_controllerFactory,
actionDescriptor,
_inputFormatters,
_outputFormatters,
_argumentBinder,
_modelBinders,
_modelValidatorProviders,
_valueProviderFactories,
_actionBindingContextAccessor,
_logger,
_telemetry,
_maxModelValidationErrors);
context.ActionContext,
_filterProviders,
_controllerFactory,
actionDescriptor,
_inputFormatters,
_outputFormatters,
_argumentBinder,
_modelBinders,
_modelValidatorProviders,
_valueProviderFactories,
_actionBindingContextAccessor,
_logger,
_telemetry,
_maxModelValidationErrors);
}
}
/// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context)
public void OnProvidersExecuted(ActionInvokerProviderContext context)
{
}
}

View File

@ -40,6 +40,21 @@ namespace Microsoft.AspNet.Mvc.Controllers
ActionBindingContext actionBindingContext,
object controller)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (actionBindingContext == null)
{
throw new ArgumentNullException(nameof(actionBindingContext));
}
if (controller == null)
{
throw new ArgumentNullException(nameof(controller));
}
var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor == null)
{
@ -69,10 +84,25 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
public async Task<ModelBindingResult> BindModelAsync(
[NotNull] ParameterDescriptor parameter,
[NotNull] ModelStateDictionary modelState,
[NotNull] OperationBindingContext operationContext)
ParameterDescriptor parameter,
ModelStateDictionary modelState,
OperationBindingContext operationContext)
{
if (parameter == null)
{
throw new ArgumentNullException(nameof(parameter));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
if (operationContext == null)
{
throw new ArgumentNullException(nameof(operationContext));
}
var metadata = _modelMetadataProvider.GetMetadataForType(parameter.ParameterType);
var modelBindingContext = ModelBindingContext.CreateBindingContext(
operationContext,

View File

@ -3,8 +3,6 @@
using System;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -24,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Controllers
_typeActivatorCache = typeActivatorCache;
}
/// <inheritdoc />
public virtual object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType)
public virtual object Create(ActionContext actionContext, Type controllerType)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
var serviceProvider = actionContext.HttpContext.RequestServices;
return _typeActivatorCache.CreateInstance<object>(serviceProvider, controllerType);
}

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -48,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
}
/// <inheritdoc />
public virtual object CreateController([NotNull] ActionContext actionContext)
public virtual object CreateController(ActionContext actionContext)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor == null)
{

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -48,9 +47,19 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// <param name="candidateAssemblies">The set of candidate assemblies.</param>
/// <returns><c>true</c> if the <paramref name="typeInfo"/> is a controller. Otherwise <c>false</c>.</returns>
protected internal virtual bool IsController(
[NotNull] TypeInfo typeInfo,
[NotNull] ISet<Assembly> candidateAssemblies)
TypeInfo typeInfo,
ISet<Assembly> candidateAssemblies)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (candidateAssemblies == null)
{
throw new ArgumentNullException(nameof(candidateAssemblies));
}
if (!typeInfo.IsClass)
{
return false;

View File

@ -16,7 +16,6 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Controllers
@ -62,18 +61,68 @@ namespace Microsoft.AspNet.Mvc.Controllers
"Request was short circuited at result filter '{ResultFilter}'.";
public FilterActionInvoker(
[NotNull] ActionContext actionContext,
[NotNull] IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IReadOnlyList<IInputFormatter> inputFormatters,
[NotNull] IReadOnlyList<IOutputFormatter> outputFormatters,
[NotNull] IReadOnlyList<IModelBinder> modelBinders,
[NotNull] IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
[NotNull] IReadOnlyList<IValueProviderFactory> valueProviderFactories,
[NotNull] IActionBindingContextAccessor actionBindingContextAccessor,
[NotNull] ILogger logger,
[NotNull] TelemetrySource telemetry,
ActionContext actionContext,
IReadOnlyList<IFilterProvider> filterProviders,
IReadOnlyList<IInputFormatter> inputFormatters,
IReadOnlyList<IOutputFormatter> outputFormatters,
IReadOnlyList<IModelBinder> modelBinders,
IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
IReadOnlyList<IValueProviderFactory> valueProviderFactories,
IActionBindingContextAccessor actionBindingContextAccessor,
ILogger logger,
TelemetrySource telemetry,
int maxModelValidationErrors)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (filterProviders == null)
{
throw new ArgumentNullException(nameof(filterProviders));
}
if (inputFormatters == null)
{
throw new ArgumentNullException(nameof(inputFormatters));
}
if (outputFormatters == null)
{
throw new ArgumentNullException(nameof(outputFormatters));
}
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
if (modelValidatorProviders == null)
{
throw new ArgumentNullException(nameof(modelValidatorProviders));
}
if (valueProviderFactories == null)
{
throw new ArgumentNullException(nameof(valueProviderFactories));
}
if (actionBindingContextAccessor == null)
{
throw new ArgumentNullException(nameof(actionBindingContextAccessor));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}
ActionContext = actionContext;
_filterProviders = filterProviders;
@ -120,8 +169,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
protected abstract Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext);
protected abstract Task<IDictionary<string, object>> BindActionArgumentsAsync(
[NotNull] ActionContext context,
[NotNull] ActionBindingContext bindingContext);
ActionContext context,
ActionBindingContext bindingContext);
public virtual async Task InvokeAsync()
{

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -21,8 +20,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// <param name="bindingContext">The <see cref="ActionBindingContext"/>.</param>
/// <param name="controller">The controller object which contains the action.</param>
Task<IDictionary<string, object>> BindActionArgumentsAsync(
[NotNull] ActionContext context,
[NotNull] ActionBindingContext bindingContext,
[NotNull] object controller);
ActionContext context,
ActionBindingContext bindingContext,
object controller);
}
}

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -14,8 +13,18 @@ namespace Microsoft.AspNet.Mvc.Controllers
public class ServiceBasedControllerActivator : IControllerActivator
{
/// <inheritdoc />
public object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType)
public object Create(ActionContext actionContext, Type controllerType)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
return actionContext.HttpContext.RequestServices.GetRequiredService(controllerType);
}
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers
{
@ -25,8 +25,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// Initializes a new instance of <see cref="StaticControllerTypeProvider"/>.
/// </summary>
/// <param name="controllerTypes">The sequence of controller <see cref="TypeInfo"/>.</param>
public StaticControllerTypeProvider([NotNull] IEnumerable<TypeInfo> controllerTypes)
public StaticControllerTypeProvider(IEnumerable<TypeInfo> controllerTypes)
{
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllerTypes = new List<TypeInfo>(controllerTypes);
}

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
@ -59,16 +58,21 @@ namespace Microsoft.AspNet.Mvc
public IDictionary<string, object> RouteValues { get; set; }
/// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context)
protected override void OnFormatting(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var request = context.HttpContext.Request;
var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();
var url = urlHelper.Action(
ActionName,
ControllerName,
RouteValues,
request.Scheme,
ActionName,
ControllerName,
RouteValues,
request.Scheme,
request.Host.ToUriComponent());
if (string.IsNullOrEmpty(url))

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
@ -62,8 +61,13 @@ namespace Microsoft.AspNet.Mvc
public IDictionary<string, object> RouteValues { get; set; }
/// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context)
protected override void OnFormatting(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();
var url = urlHelper.Link(RouteName, RouteValues);

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -21,9 +20,14 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="location">The location at which the content has been created.</param>
/// <param name="value">The value to format in the entity body.</param>
public CreatedResult([NotNull] string location, object value)
public CreatedResult(string location, object value)
: base(value)
{
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
Location = location;
StatusCode = StatusCodes.Status201Created;
}
@ -34,9 +38,14 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="location">The location at which the content has been created.</param>
/// <param name="value">The value to format in the entity body.</param>
public CreatedResult([NotNull] Uri location, object value)
public CreatedResult(Uri location, object value)
: base(value)
{
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
if (location.IsAbsoluteUri)
{
Location = location.AbsoluteUri;
@ -70,8 +79,13 @@ namespace Microsoft.AspNet.Mvc
}
/// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context)
protected override void OnFormatting(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
@ -20,9 +20,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerModelConvention">The <see cref="IControllerModelConvention"/> which needs to be
/// added.</param>
public static void Add(
[NotNull] this IList<IApplicationModelConvention> conventions,
[NotNull] IControllerModelConvention controllerModelConvention)
this IList<IApplicationModelConvention> conventions,
IControllerModelConvention controllerModelConvention)
{
if (conventions == null)
{
throw new ArgumentNullException(nameof(conventions));
}
if (controllerModelConvention == null)
{
throw new ArgumentNullException(nameof(controllerModelConvention));
}
conventions.Add(new ControllerApplicationModelConvention(controllerModelConvention));
}
@ -49,14 +59,24 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
/// <param name="actionModelConvention">The action convention to be applied on all actions
/// in the application.</param>
public ActionApplicationModelConvention([NotNull] IActionModelConvention actionModelConvention)
public ActionApplicationModelConvention(IActionModelConvention actionModelConvention)
{
if (actionModelConvention == null)
{
throw new ArgumentNullException(nameof(actionModelConvention));
}
_actionModelConvention = actionModelConvention;
}
/// <inheritdoc />
public void Apply([NotNull] ApplicationModel application)
public void Apply(ApplicationModel application)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
foreach (var controller in application.Controllers)
{
foreach (var action in controller.Actions)
@ -76,14 +96,24 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary>
/// <param name="controllerConvention">The controller convention to be applied on all controllers
/// in the application.</param>
public ControllerApplicationModelConvention([NotNull] IControllerModelConvention controllerConvention)
public ControllerApplicationModelConvention(IControllerModelConvention controllerConvention)
{
if (controllerConvention == null)
{
throw new ArgumentNullException(nameof(controllerConvention));
}
_controllerModelConvention = controllerConvention;
}
/// <inheritdoc />
public void Apply([NotNull] ApplicationModel application)
public void Apply(ApplicationModel application)
{
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
foreach (var controller in application.Controllers)
{
_controllerModelConvention.Apply(controller);

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -7,7 +7,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
@ -23,17 +22,37 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddMvcOptions(
[NotNull] this IMvcBuilder builder,
[NotNull] Action<MvcOptions> setupAction)
this IMvcBuilder builder,
Action<MvcOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>(setupAction);
return builder;
}
public static IMvcBuilder AddFormatterMappings(
[NotNull] this IMvcBuilder builder,
[NotNull] Action<FormatterMappings> setupAction)
this IMvcBuilder builder,
Action<FormatterMappings> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>((options) => setupAction(options.FormatterMappings));
return builder;
}
@ -47,9 +66,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <paramref name="services"/> and used for controller discovery.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddControllersAsServices(
[NotNull] this IMvcBuilder builder,
[NotNull] IEnumerable<Type> controllerTypes)
this IMvcBuilder builder,
IEnumerable<Type> controllerTypes)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes);
return builder;
}
@ -62,9 +91,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerAssemblies">Assemblies to scan.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddControllersAsServices(
[NotNull] this IMvcBuilder builder,
[NotNull] IEnumerable<Assembly> controllerAssemblies)
this IMvcBuilder builder,
IEnumerable<Assembly> controllerAssemblies)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerAssemblies == null)
{
throw new ArgumentNullException(nameof(controllerAssemblies));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies);
return builder;
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
@ -23,9 +22,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddMvcOptions(
[NotNull] this IMvcCoreBuilder builder,
[NotNull] Action<MvcOptions> setupAction)
this IMvcCoreBuilder builder,
Action<MvcOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>(setupAction);
return builder;
}
@ -94,9 +103,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <paramref name="services"/> and used for controller discovery.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddControllersAsServices(
[NotNull] this IMvcCoreBuilder builder,
[NotNull] IEnumerable<Type> controllerTypes)
this IMvcCoreBuilder builder,
IEnumerable<Type> controllerTypes)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes);
return builder;
}
@ -109,9 +128,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerAssemblies">Assemblies to scan.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddControllersAsServices(
[NotNull] this IMvcCoreBuilder builder,
[NotNull] IEnumerable<Assembly> controllerAssemblies)
this IMvcCoreBuilder builder,
IEnumerable<Assembly> controllerAssemblies)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerAssemblies == null)
{
throw new ArgumentNullException(nameof(controllerAssemblies));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies);
return builder;
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -16,22 +16,31 @@ using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.Framework.DependencyInjection
{
public static class MvcCoreServiceCollectionExtensions
{
public static IMvcCoreBuilder AddMvcCore([NotNull] this IServiceCollection services)
public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
return AddMvcCore(services, setupAction: null);
}
public static IMvcCoreBuilder AddMvcCore(
[NotNull] this IServiceCollection services,
this IServiceCollection services,
Action<MvcOptions> setupAction)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
ConfigureDefaultServices(services);
AddMvcCoreServices(services);

View File

@ -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
{
/// <summary>
@ -11,15 +9,8 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
public class EmptyResult : ActionResult
{
private static readonly EmptyResult _singleton = new EmptyResult();
internal static EmptyResult Instance
{
get { return _singleton; }
}
/// <inheritdoc />
public override void ExecuteResult([NotNull] ActionContext context)
public override void ExecuteResult(ActionContext context)
{
}
}

View File

@ -6,7 +6,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -26,9 +25,17 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="fileContents">The bytes that represent the file contents.</param>
/// <param name="contentType">The Content-Type header of the response.</param>
public FileContentResult([NotNull] byte[] fileContents, [NotNull] string contentType)
public FileContentResult(byte[] fileContents, string contentType)
: this(fileContents, new MediaTypeHeaderValue(contentType))
{
if (fileContents == null)
{
throw new ArgumentNullException(nameof(fileContents));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
}
/// <summary>
@ -38,9 +45,19 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="fileContents">The bytes that represent the file contents.</param>
/// <param name="contentType">The Content-Type header of the response.</param>
public FileContentResult([NotNull] byte[] fileContents, [NotNull] MediaTypeHeaderValue contentType)
public FileContentResult(byte[] fileContents, MediaTypeHeaderValue contentType)
: base(contentType)
{
if (fileContents == null)
{
throw new ArgumentNullException(nameof(fileContents));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
FileContents = fileContents;
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -22,9 +22,13 @@ namespace Microsoft.AspNet.Mvc
/// the provided <paramref name="contentType"/>.
/// </summary>
/// <param name="contentType">The Content-Type header of the response.</param>
protected FileResult([NotNull] string contentType)
protected FileResult(string contentType)
: this(new MediaTypeHeaderValue(contentType))
{
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
}
/// <summary>
@ -32,8 +36,13 @@ namespace Microsoft.AspNet.Mvc
/// the provided <paramref name="contentType"/>.
/// </summary>
/// <param name="contentType">The Content-Type header of the response.</param>
protected FileResult([NotNull] MediaTypeHeaderValue contentType)
protected FileResult(MediaTypeHeaderValue contentType)
{
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ContentType = contentType;
}
@ -52,8 +61,13 @@ namespace Microsoft.AspNet.Mvc
}
/// <inheritdoc />
public override Task ExecuteResultAsync([NotNull] ActionContext context)
public override Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var response = context.HttpContext.Response;
response.ContentType = ContentType.ToString();

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
@ -30,7 +29,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="fileStream">The stream with the file.</param>
/// <param name="contentType">The Content-Type header of the response.</param>
public FileStreamResult([NotNull] Stream fileStream, [NotNull] string contentType)
public FileStreamResult(Stream fileStream, string contentType)
: this(fileStream, new MediaTypeHeaderValue(contentType))
{
}
@ -42,9 +41,19 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="fileStream">The stream with the file.</param>
/// <param name="contentType">The Content-Type header of the response.</param>
public FileStreamResult([NotNull] Stream fileStream, [NotNull] MediaTypeHeaderValue contentType)
public FileStreamResult(Stream fileStream, MediaTypeHeaderValue contentType)
: base(contentType)
{
if (fileStream == null)
{
throw new ArgumentNullException(nameof(fileStream));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
FileStream = fileStream;
}

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -13,18 +12,28 @@ namespace Microsoft.AspNet.Mvc.Filters
{
public int Order { get; set; }
public virtual void OnActionExecuting([NotNull] ActionExecutingContext context)
public virtual void OnActionExecuting(ActionExecutingContext context)
{
}
public virtual void OnActionExecuted([NotNull] ActionExecutedContext context)
public virtual void OnActionExecuted(ActionExecutedContext context)
{
}
public virtual async Task OnActionExecutionAsync(
[NotNull] ActionExecutingContext context,
[NotNull] ActionExecutionDelegate next)
ActionExecutingContext context,
ActionExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnActionExecuting(context);
if (context.Result == null)
{
@ -32,18 +41,28 @@ namespace Microsoft.AspNet.Mvc.Filters
}
}
public virtual void OnResultExecuting([NotNull] ResultExecutingContext context)
public virtual void OnResultExecuting(ResultExecutingContext context)
{
}
public virtual void OnResultExecuted([NotNull] ResultExecutedContext context)
public virtual void OnResultExecuted(ResultExecutedContext context)
{
}
public virtual async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next)
ResultExecutingContext context,
ResultExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnResultExecuting(context);
if (!context.Cancel)
{

View File

@ -5,7 +5,6 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -15,23 +14,38 @@ namespace Microsoft.AspNet.Mvc.Filters
{
public int Order { get; set; }
public virtual Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
public virtual Task OnAuthorizationAsync(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
OnAuthorization(context);
return TaskCache.CompletedTask;
}
public virtual void OnAuthorization([NotNull] AuthorizationContext context)
public virtual void OnAuthorization(AuthorizationContext context)
{
}
protected virtual bool HasAllowAnonymous([NotNull] AuthorizationContext context)
protected virtual bool HasAllowAnonymous(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return context.Filters.Any(item => item is IAllowAnonymous);
}
protected virtual void Fail([NotNull] AuthorizationContext context)
protected virtual void Fail(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Result = new HttpUnauthorizedResult();
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
@ -19,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// Authorize filter for a specific policy.
/// </summary>
/// <param name="policy">Authorization policy to be used.</param>
public AuthorizeFilter([NotNull] AuthorizationPolicy policy)
public AuthorizeFilter(AuthorizationPolicy policy)
{
if (policy == null)
{
throw new ArgumentNullException(nameof(policy));
}
Policy = policy;
}
@ -30,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Filters
public AuthorizationPolicy Policy { get; private set; }
/// <inheritdoc />
public virtual async Task OnAuthorizationAsync([NotNull] Filters.AuthorizationContext context)
public virtual async Task OnAuthorizationAsync(Filters.AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Build a ClaimsPrincipal with the Policy's required authentication types
if (Policy.ActiveAuthenticationSchemes != null && Policy.ActiveAuthenticationSchemes.Any())
{

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <inheritdoc />
public async Task OnActionExecutionAsync(
[NotNull] ActionExecutingContext context,
[NotNull] ActionExecutionDelegate next)
ActionExecutingContext context,
ActionExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
var controller = context.Controller;
if (controller == null)
{

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <inheritdoc />
public async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next)
ResultExecutingContext context,
ResultExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
var controller = context.Controller;
if (controller == null)
{

View File

@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Filters
}
/// <inheritdoc />
public void OnProvidersExecuting([NotNull] FilterProviderContext context)
public void OnProvidersExecuting(FilterProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
{
// Perf: Avoid allocations
@ -29,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Filters
}
/// <inheritdoc />
public void OnProvidersExecuted([NotNull] FilterProviderContext context)
public void OnProvidersExecuted(FilterProviderContext context)
{
}

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -13,13 +12,18 @@ namespace Microsoft.AspNet.Mvc.Filters
{
public int Order { get; set; }
public virtual Task OnExceptionAsync([NotNull] ExceptionContext context)
public virtual Task OnExceptionAsync(ExceptionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
OnException(context);
return TaskCache.CompletedTask;
}
public virtual void OnException([NotNull] ExceptionContext context)
public virtual void OnException(ExceptionContext context)
{
}
}

View File

@ -1,11 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.ObjectModel;
using System.Reflection;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>.
/// Use <see cref="AddService(Type)"/> to register a service as a filter.
/// </remarks>
public IFilterMetadata Add([NotNull] Type filterType)
public IFilterMetadata Add(Type filterType)
{
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
return Add(filterType, order: 0);
}
@ -37,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>.
/// Use <see cref="AddService(Type)"/> to register a service as a filter.
/// </remarks>
public IFilterMetadata Add([NotNull] Type filterType, int order)
public IFilterMetadata Add(Type filterType, int order)
{
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
if (!typeof(IFilterMetadata).IsAssignableFrom(filterType))
{
var message = Resources.FormatTypeMustDeriveFromType(
@ -62,8 +71,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Add(Type)"/> to register a service that will be created via
/// type activation.
/// </remarks>
public IFilterMetadata AddService([NotNull] Type filterType)
public IFilterMetadata AddService(Type filterType)
{
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
return AddService(filterType, order: 0);
}
@ -78,8 +92,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Add(Type)"/> to register a service that will be created via
/// type activation.
/// </remarks>
public IFilterMetadata AddService([NotNull] Type filterType, int order)
public IFilterMetadata AddService(Type filterType, int order)
{
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
if (!typeof(IFilterMetadata).GetTypeInfo().IsAssignableFrom(filterType.GetTypeInfo()))
{
var message = Resources.FormatTypeMustDeriveFromType(

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters
get { return _comparer; }
}
public int Compare([NotNull]FilterDescriptor x, [NotNull]FilterDescriptor y)
public int Compare(FilterDescriptor x, FilterDescriptor y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.Order == y.Order)
{
return x.Scope.CompareTo(y.Scope);

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters
get { return _comparer; }
}
public int Compare([NotNull] FilterItem x, [NotNull] FilterItem y)
public int Compare(FilterItem x, FilterItem y)
{
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
return FilterDescriptorOrderComparer.Comparer.Compare(x.Descriptor, y.Descriptor);
}
}

View File

@ -6,7 +6,6 @@ using System.Globalization;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Filters
@ -74,8 +73,13 @@ namespace Microsoft.AspNet.Mvc.Filters
}
// <inheritdoc />
public void OnActionExecuting([NotNull] ActionExecutingContext context)
public void OnActionExecuting(ActionExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// If there are more filters which can override the values written by this filter,
// then skip execution of this filter.
if (IsOverridden(context))
@ -137,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.Filters
CultureInfo.InvariantCulture,
"{0}{1}max-age={2}",
cacheControlValue,
cacheControlValue != null? "," : null,
cacheControlValue != null ? "," : null,
Duration);
if (cacheControlValue != null)
@ -148,13 +152,18 @@ namespace Microsoft.AspNet.Mvc.Filters
}
// <inheritdoc />
public void OnActionExecuted([NotNull]ActionExecutedContext context)
public void OnActionExecuted(ActionExecutedContext context)
{
}
// internal for Unit Testing purposes.
internal bool IsOverridden([NotNull] ActionExecutingContext context)
internal bool IsOverridden(ActionExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Return true if there are any filters which are after the current filter. In which case the current
// filter should be skipped.
return context.Filters.OfType<IResponseCacheFilter>().Last() != this;

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters
{
@ -12,18 +11,28 @@ namespace Microsoft.AspNet.Mvc.Filters
{
public int Order { get; set; }
public virtual void OnResultExecuting([NotNull] ResultExecutingContext context)
public virtual void OnResultExecuting(ResultExecutingContext context)
{
}
public virtual void OnResultExecuted([NotNull] ResultExecutedContext context)
public virtual void OnResultExecuted(ResultExecutedContext context)
{
}
public virtual async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next)
ResultExecutingContext context,
ResultExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnResultExecuting(context);
if (!context.Cancel)
{

View File

@ -5,7 +5,6 @@ using System;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
/// <returns>An instance of <see cref="FormatFilter"/>.</returns>
public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider)
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
return serviceProvider.GetRequiredService<FormatFilter>();
}
}

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
@ -58,8 +58,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// 2. If there is a conflicting producesFilter.
/// </summary>
/// <param name="context">The <see cref="ResourceExecutingContext"/>.</param>
public void OnResourceExecuting([NotNull] ResourceExecutingContext context)
public void OnResourceExecuting(ResourceExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (!IsActive)
{
return; // no format specified by user, so the filter is muted
@ -92,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
}
/// <inheritdoc />
public void OnResourceExecuted([NotNull] ResourceExecutedContext context)
public void OnResourceExecuted(ResourceExecutedContext context)
{
}
@ -100,8 +105,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// Sets a Content Type on an <see cref="ObjectResult" /> using a format value from the request.
/// </summary>
/// <param name="context">The <see cref="ResultExecutingContext"/>.</param>
public void OnResultExecuting([NotNull] ResultExecutingContext context)
public void OnResultExecuting(ResultExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (!IsActive)
{
return; // no format specified by user, so the filter is muted
@ -116,8 +126,12 @@ namespace Microsoft.AspNet.Mvc.Formatters
}
/// <inheritdoc />
public void OnResultExecuted([NotNull] ResultExecutedContext context)
public void OnResultExecuted(ResultExecutedContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
private string GetFormat(ActionContext context)

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters
@ -23,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary>
/// <param name="format">The format value.</param>
/// <param name="contentType">The <see cref="MediaTypeHeaderValue"/> for the format value.</param>
public void SetMediaTypeMappingForFormat([NotNull] string format, [NotNull] MediaTypeHeaderValue contentType)
public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue contentType)
{
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ValidateContentType(contentType);
format = RemovePeriodIfPresent(format);
_map[format] = contentType.CopyAsReadOnly();
@ -35,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary>
/// <param name="format">The format value.</param>
/// <returns>The <see cref="MediaTypeHeaderValue"/> for input format.</returns>
public MediaTypeHeaderValue GetMediaTypeMappingForFormat([NotNull] string format)
public MediaTypeHeaderValue GetMediaTypeMappingForFormat(string format)
{
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
format = RemovePeriodIfPresent(format);
MediaTypeHeaderValue value = null;
@ -50,8 +64,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary>
/// <param name="format">The format value.</param>
/// <returns><c>true</c> if the format is successfully found and cleared; otherwise, <c>false</c>.</returns>
public bool ClearMediaTypeMappingForFormat([NotNull] string format)
public bool ClearMediaTypeMappingForFormat(string format)
{
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
format = RemovePeriodIfPresent(format);
return _map.Remove(format);
}

View File

@ -9,7 +9,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters
@ -102,8 +101,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// <param name="context">The formatter context associated with the call.
/// </param>
/// <returns>The <see cref="Encoding"/> to use when reading the request or writing the response.</returns>
public virtual Encoding SelectCharacterEncoding([NotNull] OutputFormatterContext context)
public virtual Encoding SelectCharacterEncoding(OutputFormatterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var request = context.HttpContext.Request;
var encoding = MatchAcceptCharacterEncoding(request.GetTypedHeaders().AcceptCharset);
if (encoding == null)
@ -125,8 +129,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
}
/// <inheritdoc />
public virtual bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType)
public virtual bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var runtimeType = context.Object == null ? null : context.Object.GetType();
if (!CanWriteType(context.DeclaredType, runtimeType))
{
@ -158,8 +167,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
}
/// <inheritdoc />
public Task WriteAsync([NotNull] OutputFormatterContext context)
public Task WriteAsync(OutputFormatterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
WriteResponseHeaders(context);
return WriteResponseBodyAsync(context);
}
@ -168,8 +182,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// Sets the headers on <see cref="Microsoft.AspNet.Http.HttpResponse"/> object.
/// </summary>
/// <param name="context">The formatter context associated with the call.</param>
public virtual void WriteResponseHeaders([NotNull] OutputFormatterContext context)
public virtual void WriteResponseHeaders(OutputFormatterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var selectedMediaType = context.SelectedContentType;
// If content type is not set then set it based on supported media types.
@ -211,7 +230,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary>
/// <param name="context">The formatter context associated with the call.</param>
/// <returns>A task which can write the response body.</returns>
public abstract Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context);
public abstract Task WriteResponseBodyAsync(OutputFormatterContext context);
private Encoding MatchAcceptCharacterEncoding(IList<StringWithQualityHeaderValue> acceptCharsetHeaders)
{

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters
@ -15,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
public class StreamOutputFormatter : IOutputFormatter
{
/// <inheritdoc />
public bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType)
public bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Ignore the passed in content type, if the object is a Stream.
if (context.Object is Stream)
{
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
}
/// <inheritdoc />
public async Task WriteAsync([NotNull] OutputFormatterContext context)
public async Task WriteAsync(OutputFormatterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
using (var valueAsStream = ((Stream)context.Object))
{
var response = context.HttpContext.Response;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
@ -23,6 +24,11 @@ namespace Microsoft.AspNet.Mvc.Formatters
public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Ignore the passed in content type, if the object is string
// always return it as a text/plain format.
if (context.DeclaredType == typeof(string))
@ -40,6 +46,11 @@ namespace Microsoft.AspNet.Mvc.Formatters
public override Task WriteResponseBodyAsync(OutputFormatterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var valueAsString = (string)context.Object;
if (string.IsNullOrEmpty(valueAsString))
{

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpDeleteAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpDeleteAttribute([NotNull] string template)
public HttpDeleteAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpGetAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpGetAttribute([NotNull] string template)
public HttpGetAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

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.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpHeadAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpHeadAttribute([NotNull] string template)
public HttpHeadAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPatchAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpPatchAttribute([NotNull] string template)
public HttpPatchAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPostAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpPostAttribute([NotNull] string template)
public HttpPostAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPutAttribute"/> with the given route template.
/// </summary>
/// <param name="template">The route template. May not be null.</param>
public HttpPutAttribute([NotNull] string template)
public HttpPutAttribute(string template)
: base(_supportedMethods, template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
}
}
}

View File

@ -1,11 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -31,8 +30,18 @@ namespace Microsoft.AspNet.Mvc
{
}
public HttpResponseStreamWriter([NotNull] Stream stream, [NotNull] Encoding encoding, int bufferSize)
public HttpResponseStreamWriter(Stream stream, Encoding encoding, int bufferSize)
{
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}
_stream = stream;
Encoding = encoding;
_encoder = encoding.GetEncoder();

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Mvc
{
@ -27,8 +27,13 @@ namespace Microsoft.AspNet.Mvc
public int StatusCode { get; private set; }
/// <inheritdoc />
public override void ExecuteResult([NotNull] ActionContext context)
public override void ExecuteResult(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.HttpContext.Response.StatusCode = StatusCode;
}
}

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="actionContext">The context object for the generated URLs for an action method.</param>
/// <returns>The fully qualified or absolute URL to an action method.</returns>
string Action([NotNull] UrlActionContext actionContext);
string Action(UrlActionContext actionContext);
/// <summary>
/// Converts a virtual (relative) path to an application absolute path.
@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="routeContext">The context object for the generated URLs for a route.</param>
/// <returns>The fully qualified or absolute URL.</returns>
string RouteUrl([NotNull] UrlRouteContext routeContext);
string RouteUrl(UrlRouteContext routeContext);
/// <summary>
/// Generates an absolute URL using the specified route name and values.

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure
{
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// </summary>
/// <param name="items">The result of action discovery</param>
/// <param name="version">The unique version of discovered actions.</param>
public ActionDescriptorsCollection([NotNull] IReadOnlyList<ActionDescriptor> items, int version)
public ActionDescriptorsCollection(IReadOnlyList<ActionDescriptor> items, int version)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = items;
Version = version;
}

View File

@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Infrastructure
@ -35,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
_logger = loggerFactory.CreateLogger<DefaultActionSelector>();
}
public Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context)
public Task<ActionDescriptor> SelectAsync(RouteContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var tree = _decisionTreeProvider.DecisionTree;
var matchingRouteConstraints = tree.Select(context.RouteData.Values);
@ -169,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
_logger.LogVerbose(
"Action '{ActionDisplayName}' with id '{ActionId}' did not match the " +
"constraint '{ActionConstraint}'",
"constraint '{ActionConstraint}'",
candidate.Action.DisplayName,
candidate.Action.Id,
constraint);
@ -216,8 +220,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
// any link - this gives WebFX a chance to 'veto' the values provided by a route.
//
// This method does not take httpmethod or dynamic action constraints into account.
public virtual bool HasValidAction([NotNull] VirtualPathContext context)
public virtual bool HasValidAction(VirtualPathContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.ProvidedValues == null)
{
// We need the route's values to be able to double check our work.

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Concurrent;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure
{
@ -21,9 +20,19 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// <inheritdoc/>
public TInstance CreateInstance<TInstance>(
[NotNull] IServiceProvider serviceProvider,
[NotNull] Type implementationType)
IServiceProvider serviceProvider,
Type implementationType)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
if (implementationType == null)
{
throw new ArgumentNullException(nameof(implementationType));
}
var createFactory = _typeActivatorCache.GetOrAdd(implementationType, _createFactory);
return (TInstance)createFactory(serviceProvider, arguments: null);
}

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Infrastructure
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
private ILogger _logger;
private TelemetrySource _telemetry;
public VirtualPathData GetVirtualPath([NotNull] VirtualPathContext context)
public VirtualPathData GetVirtualPath(VirtualPathContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
EnsureServices(context.Context);
// The contract of this method is to check that the values coming in from the route are valid;
@ -35,8 +39,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
return null;
}
public async Task RouteAsync([NotNull] RouteContext context)
public async Task RouteAsync(RouteContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var services = context.HttpContext.RequestServices;
// Verify if AddMvc was done before calling UseMvc
@ -75,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{
_telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.BeforeAction",
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData});
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
}
using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id))
@ -106,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{
var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor);
_actionContextAccessor.ActionContext = actionContext;
var invoker = _actionInvokerFactory.CreateInvoker(actionContext);
if (invoker == null)
{

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure
{
@ -30,9 +29,14 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// or <see cref="RouteKeyHandling.DenyKey"/>.
/// </param>
protected RouteConstraintAttribute(
[NotNull] string routeKey,
string routeKey,
RouteKeyHandling keyHandling)
{
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
RouteKey = routeKey;
RouteKeyHandling = keyHandling;
@ -56,10 +60,20 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// Set to true to negate this constraint on all actions that do not define a behavior for this route key.
/// </param>
protected RouteConstraintAttribute(
[NotNull]string routeKey,
[NotNull]string routeValue,
string routeKey,
string routeValue,
bool blockNonAttributedActions)
{
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
if (routeValue == null)
{
throw new ArgumentNullException(nameof(routeValue));
}
RouteKey = routeKey;
RouteValue = routeValue;
BlockNonAttributedActions = blockNonAttributedActions;

View File

@ -1,15 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal
{
public class MvcBuilder : IMvcBuilder
{
public MvcBuilder([NotNull] IServiceCollection services)
public MvcBuilder(IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
Services = services;
}

View File

@ -1,15 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal
{
public class MvcCoreBuilder : IMvcCoreBuilder
{
public MvcCoreBuilder([NotNull] IServiceCollection services)
public MvcCoreBuilder(IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
Services = services;
}

View File

@ -1,13 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System;
#endif
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal
{
@ -24,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Internal
/// Initializes a new <see cref="NonDisposableStream"/>.
/// </summary>
/// <param name="innerStream">The stream which should not be closed or flushed.</param>
public NonDisposableStream([NotNull] Stream innerStream)
public NonDisposableStream(Stream innerStream)
{
if (innerStream == null)
{
throw new ArgumentNullException(nameof(innerStream));
}
_innerStream = innerStream;
}

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class ArrayModelBinder<TElement> : CollectionModelBinder<TElement>
{
/// <inheritdoc />
public override Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public override Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
if (bindingContext.ModelMetadata.IsReadOnly)
{
return ModelBindingResult.NoResultAsync;
@ -51,8 +55,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
}
/// <inheritdoc />
protected override void CopyToModel([NotNull] object target, IEnumerable<TElement> sourceCollection)
protected override void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
// Do not attempt to copy values into an array because an array's length is immutable. This choice is also
// consistent with MutableObjectModelBinder's handling of a read-only array property.
}

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -33,8 +31,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// The <see cref="ModelBinding.BindingSource"/>. Must be a single-source (non-composite) with
/// <see cref="ModelBinding.BindingSource.IsGreedy"/> equal to <c>false</c>.
/// </param>
public BindingSourceValueProvider([NotNull] BindingSource bindingSource)
public BindingSourceValueProvider(BindingSource bindingSource)
{
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (bindingSource.IsGreedy)
{
var message = Resources.FormatBindingSource_CannotBeGreedy(
@ -68,6 +71,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc />
public virtual IValueProvider Filter(BindingSource bindingSource)
{
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (bindingSource.CanAcceptDataFrom(BindingSource))
{
return this;

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -42,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <returns>
/// A <see cref="Task{ModelBindingResult}"/> which when completed returns a <see cref="ModelBindingResult"/>.
/// </returns>
private async Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBindingContext bindingContext)
private async Task<ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// For compatibility with MVC 5.0 for top level object we want to consider an empty key instead of
// the parameter name/a custom name. In all other cases (like when binding body to a property) we
// consider the entire ModelName as a prefix.

View File

@ -3,7 +3,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -13,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class ByteArrayModelBinder : IModelBinder
{
/// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>.

View File

@ -12,7 +12,6 @@ using System.Reflection;
#endif
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class CollectionModelBinder<TElement> : ICollectionModelBinder
{
/// <inheritdoc />
public virtual async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public virtual async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
ModelBindingHelper.ValidateBindingContext(bindingContext);
var model = bindingContext.Model;
@ -303,8 +307,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="sourceCollection">
/// Collection of values retrieved from value providers. Or <c>null</c> if nothing was bound.
/// </param>
protected virtual void CopyToModel([NotNull] object target, IEnumerable<TElement> sourceCollection)
protected virtual void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
var targetCollection = target as ICollection<TElement>;
Debug.Assert(targetCollection != null, "This binder is instantiated only for ICollection<T> model types.");

View File

@ -5,9 +5,7 @@ using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -25,16 +23,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// Initializes a new instance of the CompositeModelBinder class.
/// </summary>
/// <param name="modelBinders">A collection of <see cref="IModelBinder"/> instances.</param>
public CompositeModelBinder([NotNull] IEnumerable<IModelBinder> modelBinders)
public CompositeModelBinder(IEnumerable<IModelBinder> modelBinders)
{
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
ModelBinders = new List<IModelBinder>(modelBinders);
}
/// <inheritdoc />
public IReadOnlyList<IModelBinder> ModelBinders { get; }
public virtual Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public virtual Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var newBindingContext = CreateNewBindingContext(bindingContext);
if (newBindingContext == null)
{

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -47,9 +46,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// created.
/// </returns>
public static async Task<CompositeValueProvider> CreateAsync(
[NotNull] IEnumerable<IValueProviderFactory> factories,
[NotNull] ValueProviderFactoryContext context)
IEnumerable<IValueProviderFactory> factories,
ValueProviderFactoryContext context)
{
if (factories == null)
{
throw new ArgumentNullException(nameof(factories));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var composite = new CompositeValueProvider();
foreach (var valueProvidersFactory in factories)
{
@ -114,20 +123,35 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
}
/// <inheritdoc />
protected override void InsertItem(int index, [NotNull] IValueProvider item)
protected override void InsertItem(int index, IValueProvider item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
base.InsertItem(index, item);
}
/// <inheritdoc />
protected override void SetItem(int index, [NotNull] IValueProvider item)
protected override void SetItem(int index, IValueProvider item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
base.SetItem(index, item);
}
/// <inheritdoc />
public IValueProvider Filter(BindingSource bindingSource)
{
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
var filteredValueProviders = new List<IValueProvider>();
foreach (var valueProvider in this.OfType<IBindingSourceValueProvider>())
{

View File

@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -12,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// An <see cref="IValueProvider"/> adapter for data stored in an
/// <see cref="IDictionary{string, object}"/>.
/// </summary>
public class DictionaryBasedValueProvider: BindingSourceValueProvider
public class DictionaryBasedValueProvider : BindingSourceValueProvider
{
private readonly IDictionary<string, object> _values;
private PrefixContainer _prefixContainer;
@ -23,10 +22,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
/// <param name="values">The values.</param>
public DictionaryBasedValueProvider(
[NotNull] BindingSource bindingSource,
[NotNull] IDictionary<string, object> values)
BindingSource bindingSource,
IDictionary<string, object> values)
: base(bindingSource)
{
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
_values = values;
}
@ -50,8 +59,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
}
/// <inheritdoc />
public override ValueProviderResult GetValue([NotNull] string key)
public override ValueProviderResult GetValue(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
object value;
if (_values.TryGetValue(key, out value))
{

View File

@ -10,7 +10,6 @@ using System.Reflection;
#endif
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding
{
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class DictionaryModelBinder<TKey, TValue> : CollectionModelBinder<KeyValuePair<TKey, TValue>>
{
/// <inheritdoc />
public override async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public override async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var result = await base.BindModelAsync(bindingContext);
if (!result.IsModelSet)
{

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
@ -22,6 +23,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetBindingMetadata(BindingMetadataProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Don't bother with ModelBindingMessageProvider copy constructor. No other provider can change the
// delegates.
context.BindingMetadata.ModelBindingMessageProvider = _messageProvider;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class FormCollectionModelBinder : IModelBinder
{
/// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>.

View File

@ -11,7 +11,6 @@ using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.ModelBinding
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class FormFileModelBinder : IModelBinder
{
/// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext)
public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>.
@ -38,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
}
private async Task<ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext)
{
{
object value;
if (bindingContext.ModelType == typeof(IFormFile))
{
@ -56,13 +60,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Debug.Fail("We shouldn't be called without a matching type.");
return ModelBindingResult.NoResult;
}
if (value == null)
{
return ModelBindingResult.Failed(bindingContext.ModelName);
}
else
{
{
bindingContext.ValidationState.Add(value, new ValidationStateEntry() { SuppressValidation = true });
bindingContext.ModelState.SetModelValue(
bindingContext.ModelName,

Some files were not shown because too many files have changed in this diff Show More