// 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;
namespace Microsoft.AspNetCore.Mvc.Routing
{
///
/// Identifies an action that only supports a given set of HTTP methods.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class HttpMethodAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider
{
private readonly IEnumerable _httpMethods;
private int? _order;
///
/// Creates a new with the given
/// set of HTTP methods.
/// The set of supported HTTP methods.
///
public HttpMethodAttribute(IEnumerable httpMethods)
: this(httpMethods, null)
{
if (httpMethods == null)
{
throw new ArgumentNullException(nameof(httpMethods));
}
}
///
/// Creates a new with the given
/// set of HTTP methods an the given route template.
///
/// The set of supported methods.
/// The route template. May not be null.
public HttpMethodAttribute(IEnumerable httpMethods, string template)
{
if (httpMethods == null)
{
throw new ArgumentNullException(nameof(httpMethods));
}
_httpMethods = httpMethods;
Template = template;
}
///
public IEnumerable HttpMethods
{
get
{
return _httpMethods;
}
}
///
public string Template { get; private set; }
///
/// 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
{
get
{
return _order;
}
}
///
public string Name { get; set; }
}
}