Issue #1754 - Change List to IList in application model
This commit is contained in:
parent
5262dfd577
commit
fb21b736ee
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IActionConstraintMetadata> ActionConstraints { get; private set; }
|
public IList<IActionConstraintMetadata> ActionConstraints { get; private set; }
|
||||||
|
|
||||||
public MethodInfo ActionMethod { get; }
|
public MethodInfo ActionMethod { get; }
|
||||||
|
|
||||||
|
|
@ -69,12 +69,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
|
|
||||||
public ControllerModel Controller { get; set; }
|
public ControllerModel Controller { get; set; }
|
||||||
|
|
||||||
public List<IFilter> Filters { get; private set; }
|
public IList<IFilter> Filters { get; private set; }
|
||||||
|
|
||||||
public List<string> HttpMethods { get; private set; }
|
public IList<string> HttpMethods { get; private set; }
|
||||||
|
|
||||||
public List<ParameterModel> Parameters { get; private set; }
|
public IList<ParameterModel> Parameters { get; private set; }
|
||||||
|
|
||||||
public List<IRouteConstraintProvider> RouteConstraints { get; private set; }
|
public IList<IRouteConstraintProvider> RouteConstraints { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
Filters = new List<IFilter>();
|
Filters = new List<IFilter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ControllerModel> Controllers { get; private set; }
|
public IList<ControllerModel> Controllers { get; private set; }
|
||||||
|
|
||||||
public List<IFilter> Filters { get; private set; }
|
public IList<IFilter> Filters { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,9 +44,9 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
other.AttributeRoutes.Select(a => new AttributeRouteModel(a)));
|
other.AttributeRoutes.Select(a => new AttributeRouteModel(a)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IActionConstraintMetadata> ActionConstraints { get; private set; }
|
public IList<IActionConstraintMetadata> ActionConstraints { get; private set; }
|
||||||
|
|
||||||
public List<ActionModel> Actions { get; private set; }
|
public IList<ActionModel> Actions { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="ApiExplorerModel"/> for this controller.
|
/// Gets or sets the <see cref="ApiExplorerModel"/> for this controller.
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
|
|
||||||
public ApplicationModel Application { get; set; }
|
public ApplicationModel Application { get; set; }
|
||||||
|
|
||||||
public List<AttributeRouteModel> AttributeRoutes { get; private set; }
|
public IList<AttributeRouteModel> AttributeRoutes { get; private set; }
|
||||||
|
|
||||||
public IReadOnlyList<object> Attributes { get; }
|
public IReadOnlyList<object> Attributes { get; }
|
||||||
|
|
||||||
|
|
@ -63,8 +63,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
|
|
||||||
public TypeInfo ControllerType { get; private set; }
|
public TypeInfo ControllerType { get; private set; }
|
||||||
|
|
||||||
public List<IFilter> Filters { get; private set; }
|
public IList<IFilter> Filters { get; private set; }
|
||||||
|
|
||||||
public List<IRouteConstraintProvider> RouteConstraints { get; private set; }
|
public IList<IRouteConstraintProvider> RouteConstraints { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
{
|
{
|
||||||
var actionModel = new ActionModel(methodInfo, attributes);
|
var actionModel = new ActionModel(methodInfo, attributes);
|
||||||
|
|
||||||
actionModel.ActionConstraints.AddRange(attributes.OfType<IActionConstraintMetadata>());
|
AddRange(actionModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>());
|
||||||
actionModel.Filters.AddRange(attributes.OfType<IFilter>());
|
AddRange(actionModel.Filters, attributes.OfType<IFilter>());
|
||||||
|
|
||||||
var actionName = attributes.OfType<ActionNameAttribute>().FirstOrDefault();
|
var actionName = attributes.OfType<ActionNameAttribute>().FirstOrDefault();
|
||||||
if (actionName?.Name != null)
|
if (actionName?.Name != null)
|
||||||
|
|
@ -280,13 +280,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpMethods = attributes.OfType<IActionHttpMethodProvider>();
|
var httpMethods = attributes.OfType<IActionHttpMethodProvider>();
|
||||||
actionModel.HttpMethods.AddRange(
|
AddRange(actionModel.HttpMethods,
|
||||||
httpMethods
|
httpMethods
|
||||||
.Where(a => a.HttpMethods != null)
|
.Where(a => a.HttpMethods != null)
|
||||||
.SelectMany(a => a.HttpMethods)
|
.SelectMany(a => a.HttpMethods)
|
||||||
.Distinct());
|
.Distinct());
|
||||||
|
|
||||||
actionModel.RouteConstraints.AddRange(attributes.OfType<IRouteConstraintProvider>());
|
AddRange(actionModel.RouteConstraints, attributes.OfType<IRouteConstraintProvider>());
|
||||||
|
|
||||||
var routeTemplateProvider =
|
var routeTemplateProvider =
|
||||||
attributes
|
attributes
|
||||||
|
|
@ -329,5 +329,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
routeTemplateProvider.Order == null &&
|
routeTemplateProvider.Order == null &&
|
||||||
routeTemplateProvider.Name == null;
|
routeTemplateProvider.Name == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void AddRange<T>(IList<T> list, IEnumerable<T> items)
|
||||||
|
{
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
list.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNet.Mvc.Description;
|
using Microsoft.AspNet.Mvc.Description;
|
||||||
|
|
@ -120,11 +121,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
typeInfo.Name.Substring(0, typeInfo.Name.Length - "Controller".Length) :
|
typeInfo.Name.Substring(0, typeInfo.Name.Length - "Controller".Length) :
|
||||||
typeInfo.Name;
|
typeInfo.Name;
|
||||||
|
|
||||||
controllerModel.ActionConstraints.AddRange(attributes.OfType<IActionConstraintMetadata>());
|
AddRange(controllerModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>());
|
||||||
controllerModel.Filters.AddRange(attributes.OfType<IFilter>());
|
AddRange(controllerModel.Filters, attributes.OfType<IFilter>());
|
||||||
controllerModel.RouteConstraints.AddRange(attributes.OfType<IRouteConstraintProvider>());
|
AddRange(controllerModel.RouteConstraints, attributes.OfType<IRouteConstraintProvider>());
|
||||||
|
|
||||||
controllerModel.AttributeRoutes.AddRange(
|
AddRange(
|
||||||
|
controllerModel.AttributeRoutes,
|
||||||
attributes.OfType<IRouteTemplateProvider>().Select(rtp => new AttributeRouteModel(rtp)));
|
attributes.OfType<IRouteTemplateProvider>().Select(rtp => new AttributeRouteModel(rtp)));
|
||||||
|
|
||||||
var apiVisibility = attributes.OfType<IApiDescriptionVisibilityProvider>().FirstOrDefault();
|
var apiVisibility = attributes.OfType<IApiDescriptionVisibilityProvider>().FirstOrDefault();
|
||||||
|
|
@ -141,5 +143,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
|
|
||||||
return controllerModel;
|
return controllerModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void AddRange<T>(IList<T> list, IEnumerable<T> items)
|
||||||
|
{
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
list.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
public ApplicationModel BuildModel()
|
public ApplicationModel BuildModel()
|
||||||
{
|
{
|
||||||
var applicationModel = new ApplicationModel();
|
var applicationModel = new ApplicationModel();
|
||||||
applicationModel.Filters.AddRange(_globalFilters);
|
foreach (var filter in _globalFilters)
|
||||||
|
{
|
||||||
|
applicationModel.Filters.Add(filter);
|
||||||
|
}
|
||||||
|
|
||||||
var assemblies = _assemblyProvider.CandidateAssemblies;
|
var assemblies = _assemblyProvider.CandidateAssemblies;
|
||||||
var types = assemblies.SelectMany(a => a.DefinedTypes);
|
var types = assemblies.SelectMany(a => a.DefinedTypes);
|
||||||
|
|
|
||||||
|
|
@ -55,19 +55,19 @@ namespace Microsoft.AspNet.Mvc.Logging
|
||||||
/// The parameters of the action as <see cref="ParameterModelValues"/>.
|
/// The parameters of the action as <see cref="ParameterModelValues"/>.
|
||||||
/// See <see cref="ActionModel.Parameters"/>.
|
/// See <see cref="ActionModel.Parameters"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ParameterModelValues> Parameters { get; }
|
public IList<ParameterModelValues> Parameters { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The filters of the action as <see cref="FilterValues"/>.
|
/// The filters of the action as <see cref="FilterValues"/>.
|
||||||
/// See <see cref="ActionModel.Filters"/>.
|
/// See <see cref="ActionModel.Filters"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<FilterValues> Filters { get; }
|
public IList<FilterValues> Filters { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The route constraints on the controller as <see cref="RouteConstraintProviderValues"/>.
|
/// The route constraints on the controller as <see cref="RouteConstraintProviderValues"/>.
|
||||||
/// See <see cref="ControllerModel.RouteConstraints"/>.
|
/// See <see cref="ControllerModel.RouteConstraints"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<RouteConstraintProviderValues> RouteConstraints { get; set; }
|
public IList<RouteConstraintProviderValues> RouteConstraints { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The attribute route model of the action as <see cref="AttributeRouteModelValues"/>.
|
/// The attribute route model of the action as <see cref="AttributeRouteModelValues"/>.
|
||||||
|
|
@ -78,13 +78,13 @@ namespace Microsoft.AspNet.Mvc.Logging
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The http methods this action supports. See <see cref="ActionModel.HttpMethods"/>.
|
/// The http methods this action supports. See <see cref="ActionModel.HttpMethods"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> HttpMethods { get; }
|
public IList<string> HttpMethods { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The action constraints of the action as <see cref="ActionConstraintValues"/>.
|
/// The action constraints of the action as <see cref="ActionConstraintValues"/>.
|
||||||
/// See <see cref="ActionModel.ActionConstraints"/>.
|
/// See <see cref="ActionModel.ActionConstraints"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<ActionConstraintValues> ActionConstraints { get; }
|
public IList<ActionConstraintValues> ActionConstraints { get; }
|
||||||
|
|
||||||
public override string Format()
|
public override string Format()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.Actions.AddRange(newActions);
|
foreach (var action in newActions)
|
||||||
|
{
|
||||||
|
controller.Actions.Add(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsActionAttributeRouted(ActionModel action)
|
private bool IsActionAttributeRouted(ActionModel action)
|
||||||
|
|
|
||||||
|
|
@ -576,7 +576,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var action = Assert.Single(actions);
|
var action = Assert.Single(actions);
|
||||||
Assert.Equal(new string[] { "GET" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET" }, action.HttpMethods);
|
||||||
Assert.Equal("Products", action.AttributeRouteModel.Template);
|
Assert.Equal("Products", action.AttributeRouteModel.Template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,10 +595,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
Assert.Equal(2, actions.Count());
|
Assert.Equal(2, actions.Count());
|
||||||
|
|
||||||
var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products");
|
var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products");
|
||||||
Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET", "POST" }, action.HttpMethods);
|
||||||
|
|
||||||
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products");
|
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products");
|
||||||
Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET", "POST" }, action.HttpMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -616,13 +616,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
Assert.Equal(3, actions.Count());
|
Assert.Equal(3, actions.Count());
|
||||||
|
|
||||||
var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products");
|
var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products");
|
||||||
Assert.Equal(new string[] { "GET" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET" }, action.HttpMethods);
|
||||||
|
|
||||||
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products");
|
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products");
|
||||||
Assert.Equal(new string[] { "GET" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET" }, action.HttpMethods);
|
||||||
|
|
||||||
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products/Buy");
|
action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products/Buy");
|
||||||
Assert.Equal(new string[] { "POST" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "POST" }, action.HttpMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -640,10 +640,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
|
||||||
Assert.Equal(2, actions.Count());
|
Assert.Equal(2, actions.Count());
|
||||||
|
|
||||||
var action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == "Products");
|
var action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == "Products");
|
||||||
Assert.Equal(new string[] { "POST" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "POST" }, action.HttpMethods);
|
||||||
|
|
||||||
action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == null);
|
action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == null);
|
||||||
Assert.Equal(new string[] { "GET" }, action.HttpMethods);
|
Assert.Equal<string>(new string[] { "GET" }, action.HttpMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AccessibleActionModelBuilder : DefaultActionModelBuilder
|
private class AccessibleActionModelBuilder : DefaultActionModelBuilder
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue