// 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.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ApplicationModels { [DebuggerDisplay("Name={ControllerName}, Type={ControllerType.Name}," + " Routes: {AttributeRoutes.Count}, Filters: {Filters.Count}")] public class ControllerModel { public ControllerModel([NotNull] TypeInfo controllerType, [NotNull] IReadOnlyList attributes) { ControllerType = controllerType; Actions = new List(); ApiExplorer = new ApiExplorerModel(); Attributes = new List(attributes); AttributeRoutes = new List(); ActionConstraints = new List(); Filters = new List(); RouteConstraints = new List(); Properties = new Dictionary(); ControllerProperties = new List(); } public ControllerModel([NotNull] ControllerModel other) { ControllerName = other.ControllerName; ControllerType = other.ControllerType; // Still part of the same application Application = other.Application; // These are just metadata, safe to create new collections ActionConstraints = new List(other.ActionConstraints); Attributes = new List(other.Attributes); Filters = new List(other.Filters); RouteConstraints = new List(other.RouteConstraints); Properties = new Dictionary(other.Properties); // Make a deep copy of other 'model' types. Actions = new List(other.Actions.Select(a => new ActionModel(a))); ApiExplorer = new ApiExplorerModel(other.ApiExplorer); AttributeRoutes = new List( other.AttributeRoutes.Select(a => new AttributeRouteModel(a))); ControllerProperties = new List(other.ControllerProperties.Select(p => new PropertyModel(p))); } public IList ActionConstraints { get; private set; } public IList Actions { get; private set; } /// /// Gets or sets the for this controller. /// /// /// allows configuration of settings for ApiExplorer /// which apply to all actions in the controller unless overridden by . /// /// Settings applied by override settings from /// . /// public ApiExplorerModel ApiExplorer { get; set; } public ApplicationModel Application { get; set; } public IList AttributeRoutes { get; private set; } public IReadOnlyList Attributes { get; } public string ControllerName { get; set; } public TypeInfo ControllerType { get; private set; } public IList ControllerProperties { get; } public IList Filters { get; private set; } public IList RouteConstraints { get; private set; } /// /// Gets a set of properties associated with the controller. /// These properties will be copied to . /// /// /// Entries will take precedence over entries with the same key /// in . /// public IDictionary Properties { get; } } }