// 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.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Http;
using System.Web.Http.Controllers;
namespace System.Web.Http
{
///
/// Specifies what HTTP methods an action supports.
///
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "The accessor is exposed as an Collection.")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class AcceptVerbsAttribute : Attribute, IActionHttpMethodProvider
{
private readonly Collection _httpMethods;
///
/// Initializes a new instance of the class.
///
/// The HTTP method the action supports.
///
/// This is a CLS compliant constructor.
///
public AcceptVerbsAttribute(string method)
: this(new string[] { method })
{
}
///
/// Initializes a new instance of the class.
///
/// The HTTP methods the action supports.
///
/// This constructor is not CLS-compliant.
///
public AcceptVerbsAttribute(params string[] methods)
{
_httpMethods = methods != null
? new Collection(methods.Select(method => HttpMethodHelper.GetHttpMethod(method)).ToArray())
: new Collection(new HttpMethod[0]);
}
///
/// Initializes a new instance of the class.
///
/// The HTTP methods the action supports.
internal AcceptVerbsAttribute(params HttpMethod[] methods)
{
_httpMethods = new Collection(methods);
}
///
/// Gets the HTTP methods the action supports.
///
public Collection HttpMethods
{
get
{
return _httpMethods;
}
}
}
}