// 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.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; namespace Microsoft.AspNet.Mvc.ApplicationModels { [DebuggerDisplay("Name={ActionName}({Methods()}), Type={Controller.ControllerType.Name}," + " Route: {AttributeRouteModel?.Template}, Filters: {Filters.Count}")] public class ActionModel { public ActionModel([NotNull] MethodInfo actionMethod, [NotNull] IReadOnlyList attributes) { ActionMethod = actionMethod; ApiExplorer = new ApiExplorerModel(); Attributes = new List(attributes); ActionConstraints = new List(); Filters = new List(); HttpMethods = new List(); Parameters = new List(); RouteConstraints = new List(); Properties = new Dictionary(); } public ActionModel([NotNull] ActionModel other) { ActionMethod = other.ActionMethod; ActionName = other.ActionName; // Not making a deep copy of the controller, this action still belongs to the same controller. Controller = other.Controller; // These are just metadata, safe to create new collections ActionConstraints = new List(other.ActionConstraints); Attributes = new List(other.Attributes); Filters = new List(other.Filters); HttpMethods = new List(other.HttpMethods); Properties = new Dictionary(other.Properties); // Make a deep copy of other 'model' types. ApiExplorer = new ApiExplorerModel(other.ApiExplorer); Parameters = new List(other.Parameters.Select(p => new ParameterModel(p))); RouteConstraints = new List(other.RouteConstraints); if (other.AttributeRouteModel != null) { AttributeRouteModel = new AttributeRouteModel(other.AttributeRouteModel); } } public IList ActionConstraints { get; private set; } public MethodInfo ActionMethod { get; } public string ActionName { get; set; } /// /// Gets or sets the for this action. /// /// /// allows configuration of settings for ApiExplorer /// which apply to the action. /// /// Settings applied by override settings from /// and . /// public ApiExplorerModel ApiExplorer { get; set; } public AttributeRouteModel AttributeRouteModel { get; set; } public IReadOnlyList Attributes { get; } public ControllerModel Controller { get; set; } public IList Filters { get; private set; } public IList HttpMethods { get; private set; } public IList Parameters { get; private set; } public IList RouteConstraints { get; private set; } /// /// Gets a set of properties associated with the action. /// These properties will be copied to . /// /// /// Entries will take precedence over entries with the same key in /// and . /// public IDictionary Properties { get; } private string Methods() { if (HttpMethods.Count == 0) { return "All"; } return string.Join(", ", HttpMethods); } } }