forked from haoduotnt/aspnetwebstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpVerbAttribute.cs
More file actions
68 lines (59 loc) · 2.27 KB
/
HttpVerbAttribute.cs
File metadata and controls
68 lines (59 loc) · 2.27 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
68
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Routing;
namespace System.Web.Http
{
/// <summary>
/// Defines a base class for specifying that an action supports a particular HTTP method.
/// </summary>
#pragma warning disable 3015 // This is an abstract base attribute that doesn't need an accessible constructor
public abstract class HttpVerbAttribute : Attribute, IActionHttpMethodProvider, IHttpRouteInfoProvider
#pragma warning restore 3015
{
private readonly Collection<HttpMethod> _supportedMethods;
/// <summary>
/// Initializes a new instance of the <see cref="HttpVerbAttribute" /> class.
/// </summary>
/// <param name="httpMethod">The HTTP method the action supports.</param>
protected HttpVerbAttribute(HttpMethod httpMethod)
{
_supportedMethods = new Collection<HttpMethod>() { httpMethod };
}
/// <summary>
/// Initializes a new instance of the <see cref="HttpVerbAttribute" /> class.
/// </summary>
/// <param name="httpMethod">The HTTP method the action supports.</param>
/// <param name="routeTemplate">The route template describing the URI pattern to match against.</param>
protected HttpVerbAttribute(HttpMethod httpMethod, string routeTemplate)
: this(httpMethod)
{
RouteTemplate = routeTemplate;
}
/// <summary>
/// Gets the HTTP methods the action supports.
/// </summary>
public Collection<HttpMethod> HttpMethods
{
get
{
return _supportedMethods;
}
}
/// <inheritdoc />
public string RouteName { get; set; }
/// <inheritdoc />
public int RouteOrder { get; set; }
/// <inheritdoc />
public string RouteTemplate { get; private set; }
IEnumerable<HttpMethod> IHttpRouteInfoProvider.HttpMethods
{
get
{
return _supportedMethods;
}
}
}
}