// Copyright (c) Microsoft Open Technologies, Inc. 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.Routing; namespace Microsoft.AspNet.Mvc.ReflectedModelBuilder { public class ReflectedControllerModel { public ReflectedControllerModel([NotNull] TypeInfo controllerType) { ControllerType = controllerType; Actions = new List(); // CoreCLR returns IEnumerable from GetCustomAttributes - the OfType // is needed to so that the result of ToList() is List Attributes = ControllerType.GetCustomAttributes(inherit: true).OfType().ToList(); Filters = Attributes.OfType().ToList(); RouteConstraints = Attributes.OfType().ToList(); AttributeRoutes = Attributes.OfType() .Select(rtp => new ReflectedAttributeRouteModel(rtp)) .ToList(); ControllerName = controllerType.Name.EndsWith("Controller", StringComparison.Ordinal) ? controllerType.Name.Substring(0, controllerType.Name.Length - "Controller".Length) : controllerType.Name; } public List Actions { get; private set; } public List Attributes { get; private set; } public string ControllerName { get; set; } public TypeInfo ControllerType { get; private set; } public List Filters { get; private set; } public List RouteConstraints { get; private set; } public List AttributeRoutes { get; private set; } } }