forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteAttribute.cs
More file actions
58 lines (49 loc) · 1.95 KB
/
RouteAttribute.cs
File metadata and controls
58 lines (49 loc) · 1.95 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
// 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.Diagnostics.Contracts;
using System.Web.Http.Routing;
namespace System.Web.Http
{
/// <summary>
/// Place on a controller or action to expose it directly via a route.
/// When placed on a controller, it applies to actions that do not have any <see cref="RouteAttribute"/>s on them.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public sealed class RouteAttribute : Attribute, IDirectRouteFactory, IHttpRouteInfoProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="RouteAttribute" /> class.
/// </summary>
public RouteAttribute()
{
Template = String.Empty;
}
/// <summary>
/// Initializes a new instance of the <see cref="RouteAttribute" /> class.
/// </summary>
/// <param name="template">The route template describing the URI pattern to match against.</param>
public RouteAttribute(string template)
{
if (template == null)
{
throw Error.ArgumentNull("template");
}
Template = template;
}
/// <inheritdoc />
public string Name { get; set; }
/// <inheritdoc />
public int Order { get; set; }
/// <inheritdoc />
public string Template { get; private set; }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context)
{
Contract.Assert(context != null);
IDirectRouteBuilder builder = context.CreateBuilder(Template);
Contract.Assert(builder != null);
builder.Name = Name;
builder.Order = Order;
return builder.Build();
}
}
}