forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcceptVerbsAttribute.cs
More file actions
67 lines (61 loc) · 2.51 KB
/
AcceptVerbsAttribute.cs
File metadata and controls
67 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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
{
/// <summary>
/// Specifies what HTTP methods an action supports.
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "The accessor is exposed as an Collection<HttpMethod>.")]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class AcceptVerbsAttribute : Attribute, IActionHttpMethodProvider
{
private readonly Collection<HttpMethod> _httpMethods;
/// <summary>
/// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class.
/// </summary>
/// <param name="method">The HTTP method the action supports.</param>
/// <remarks>
/// This is a CLS compliant constructor.
/// </remarks>
public AcceptVerbsAttribute(string method)
: this(new string[] { method })
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class.
/// </summary>
/// <param name="methods">The HTTP methods the action supports.</param>
/// <remarks>
/// This constructor is not CLS-compliant.
/// </remarks>
public AcceptVerbsAttribute(params string[] methods)
{
_httpMethods = methods != null
? new Collection<HttpMethod>(methods.Select(method => HttpMethodHelper.GetHttpMethod(method)).ToArray())
: new Collection<HttpMethod>(new HttpMethod[0]);
}
/// <summary>
/// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class.
/// </summary>
/// <param name="methods">The HTTP methods the action supports.</param>
internal AcceptVerbsAttribute(params HttpMethod[] methods)
{
_httpMethods = new Collection<HttpMethod>(methods);
}
/// <summary>
/// Gets the HTTP methods the action supports.
/// </summary>
public Collection<HttpMethod> HttpMethods
{
get
{
return _httpMethods;
}
}
}
}