diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs index c1ea508f90..0829b27abc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ActionModel.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels } } - public List ActionConstraints { get; private set; } + public IList ActionConstraints { get; private set; } public MethodInfo ActionMethod { get; } @@ -69,12 +69,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public ControllerModel Controller { get; set; } - public List Filters { get; private set; } + public IList Filters { get; private set; } - public List HttpMethods { get; private set; } + public IList HttpMethods { get; private set; } - public List Parameters { get; private set; } + public IList Parameters { get; private set; } - public List RouteConstraints { get; private set; } + public IList RouteConstraints { get; private set; } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModel.cs index e102fbefca..cbb87b98d8 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ApplicationModel.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels Filters = new List(); } - public List Controllers { get; private set; } + public IList Controllers { get; private set; } - public List Filters { get; private set; } + public IList Filters { get; private set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs index 9b5ee6c2dd..ef22386b47 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/ControllerModel.cs @@ -44,9 +44,9 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels other.AttributeRoutes.Select(a => new AttributeRouteModel(a))); } - public List ActionConstraints { get; private set; } + public IList ActionConstraints { get; private set; } - public List Actions { get; private set; } + public IList Actions { get; private set; } /// /// Gets or sets the for this controller. @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public ApplicationModel Application { get; set; } - public List AttributeRoutes { get; private set; } + public IList AttributeRoutes { get; private set; } public IReadOnlyList Attributes { get; } @@ -63,8 +63,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels public TypeInfo ControllerType { get; private set; } - public List Filters { get; private set; } + public IList Filters { get; private set; } - public List RouteConstraints { get; private set; } + public IList RouteConstraints { get; private set; } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultActionModelBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultActionModelBuilder.cs index 4bc8b26271..d9afde3509 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultActionModelBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultActionModelBuilder.cs @@ -254,8 +254,8 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels { var actionModel = new ActionModel(methodInfo, attributes); - actionModel.ActionConstraints.AddRange(attributes.OfType()); - actionModel.Filters.AddRange(attributes.OfType()); + AddRange(actionModel.ActionConstraints, attributes.OfType()); + AddRange(actionModel.Filters, attributes.OfType()); var actionName = attributes.OfType().FirstOrDefault(); if (actionName?.Name != null) @@ -280,13 +280,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels } var httpMethods = attributes.OfType(); - actionModel.HttpMethods.AddRange( + AddRange(actionModel.HttpMethods, httpMethods .Where(a => a.HttpMethods != null) .SelectMany(a => a.HttpMethods) .Distinct()); - actionModel.RouteConstraints.AddRange(attributes.OfType()); + AddRange(actionModel.RouteConstraints, attributes.OfType()); var routeTemplateProvider = attributes @@ -329,5 +329,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels routeTemplateProvider.Order == null && routeTemplateProvider.Name == null; } + + private static void AddRange(IList list, IEnumerable items) + { + foreach (var item in items) + { + list.Add(item); + } + } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultControllerModelBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultControllerModelBuilder.cs index b8fa51f4d5..d4cb7cfed2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultControllerModelBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ApplicationModels/DefaultControllerModelBuilder.cs @@ -2,6 +2,7 @@ // 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.Description; @@ -120,11 +121,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels typeInfo.Name.Substring(0, typeInfo.Name.Length - "Controller".Length) : typeInfo.Name; - controllerModel.ActionConstraints.AddRange(attributes.OfType()); - controllerModel.Filters.AddRange(attributes.OfType()); - controllerModel.RouteConstraints.AddRange(attributes.OfType()); + AddRange(controllerModel.ActionConstraints, attributes.OfType()); + AddRange(controllerModel.Filters, attributes.OfType()); + AddRange(controllerModel.RouteConstraints, attributes.OfType()); - controllerModel.AttributeRoutes.AddRange( + AddRange( + controllerModel.AttributeRoutes, attributes.OfType().Select(rtp => new AttributeRouteModel(rtp))); var apiVisibility = attributes.OfType().FirstOrDefault(); @@ -141,5 +143,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels return controllerModel; } + + private static void AddRange(IList list, IEnumerable items) + { + foreach (var item in items) + { + list.Add(item); + } + } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ControllerActionDescriptorProvider.cs b/src/Microsoft.AspNet.Mvc.Core/ControllerActionDescriptorProvider.cs index c727fea474..347591e91b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ControllerActionDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ControllerActionDescriptorProvider.cs @@ -61,7 +61,10 @@ namespace Microsoft.AspNet.Mvc public ApplicationModel BuildModel() { var applicationModel = new ApplicationModel(); - applicationModel.Filters.AddRange(_globalFilters); + foreach (var filter in _globalFilters) + { + applicationModel.Filters.Add(filter); + } var assemblies = _assemblyProvider.CandidateAssemblies; var types = assemblies.SelectMany(a => a.DefinedTypes); diff --git a/src/Microsoft.AspNet.Mvc.Core/Logging/ActionModelValues.cs b/src/Microsoft.AspNet.Mvc.Core/Logging/ActionModelValues.cs index 661a2cab65..f5f8d599aa 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Logging/ActionModelValues.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Logging/ActionModelValues.cs @@ -55,19 +55,19 @@ namespace Microsoft.AspNet.Mvc.Logging /// The parameters of the action as . /// See . /// - public List Parameters { get; } + public IList Parameters { get; } /// /// The filters of the action as . /// See . /// - public List Filters { get; } + public IList Filters { get; } /// /// The route constraints on the controller as . /// See . /// - public List RouteConstraints { get; set; } + public IList RouteConstraints { get; set; } /// /// The attribute route model of the action as . @@ -78,13 +78,13 @@ namespace Microsoft.AspNet.Mvc.Logging /// /// The http methods this action supports. See . /// - public List HttpMethods { get; } + public IList HttpMethods { get; } /// /// The action constraints of the action as . /// See . /// - public List ActionConstraints { get; } + public IList ActionConstraints { get; } public override string Format() { diff --git a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/Conventions/WebApiActionConventionsApplicationModelConvention.cs b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/Conventions/WebApiActionConventionsApplicationModelConvention.cs index bbf47089eb..0f7b36016a 100644 --- a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/Conventions/WebApiActionConventionsApplicationModelConvention.cs +++ b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/Conventions/WebApiActionConventionsApplicationModelConvention.cs @@ -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) diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultActionModelBuilderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultActionModelBuilderTest.cs index ee81a9b625..0223c7098b 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultActionModelBuilderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ApplicationModel/DefaultActionModelBuilderTest.cs @@ -576,7 +576,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels // Assert var action = Assert.Single(actions); - Assert.Equal(new string[] { "GET" }, action.HttpMethods); + Assert.Equal(new string[] { "GET" }, action.HttpMethods); Assert.Equal("Products", action.AttributeRouteModel.Template); } @@ -595,10 +595,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels Assert.Equal(2, actions.Count()); var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products"); - Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods); + Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods); action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products"); - Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods); + Assert.Equal(new string[] { "GET", "POST" }, action.HttpMethods); } [Fact] @@ -616,13 +616,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels Assert.Equal(3, actions.Count()); var action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products"); - Assert.Equal(new string[] { "GET" }, action.HttpMethods); + Assert.Equal(new string[] { "GET" }, action.HttpMethods); action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "v2/Products"); - Assert.Equal(new string[] { "GET" }, action.HttpMethods); + Assert.Equal(new string[] { "GET" }, action.HttpMethods); action = Assert.Single(actions, a => a.AttributeRouteModel.Template == "Products/Buy"); - Assert.Equal(new string[] { "POST" }, action.HttpMethods); + Assert.Equal(new string[] { "POST" }, action.HttpMethods); } [Fact] @@ -640,10 +640,10 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels Assert.Equal(2, actions.Count()); var action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == "Products"); - Assert.Equal(new string[] { "POST" }, action.HttpMethods); + Assert.Equal(new string[] { "POST" }, action.HttpMethods); action = Assert.Single(actions, a => a.AttributeRouteModel?.Template == null); - Assert.Equal(new string[] { "GET" }, action.HttpMethods); + Assert.Equal(new string[] { "GET" }, action.HttpMethods); } private class AccessibleActionModelBuilder : DefaultActionModelBuilder