// 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; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Routing; namespace Microsoft.AspNetCore.Mvc { /// /// Specifies what HTTP methods an action supports. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public sealed class AcceptVerbsAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider { private int? _order; /// /// Initializes a new instance of the class. /// /// The HTTP method the action supports. public AcceptVerbsAttribute(string method) : this(new [] { method }) { if (method == null) { throw new ArgumentNullException(nameof(method)); } } /// /// Initializes a new instance of the class. /// /// The HTTP methods the action supports. public AcceptVerbsAttribute(params string[] methods) { HttpMethods = methods.Select(method => method.ToUpperInvariant()); } /// /// Gets the HTTP methods the action supports. /// public IEnumerable HttpMethods { get; } /// /// The route template. May be null. /// public string Route { get; set; } /// string IRouteTemplateProvider.Template => Route; /// /// Gets the route order. The order determines the order of route execution. Routes with a lower /// order value are tried first. When a route doesn't specify a value, it gets the value of the /// or a default value of 0 if the /// doesn't define a value on the controller. /// public int Order { get { return _order ?? 0; } set { _order = value; } } /// int? IRouteTemplateProvider.Order => _order; /// public string Name { get; set; } } }