forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpRouteExtensions.cs
More file actions
109 lines (88 loc) · 3.39 KB
/
Copy pathHttpRouteExtensions.cs
File metadata and controls
109 lines (88 loc) · 3.39 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 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.Generic;
using System.Diagnostics.Contracts;
using System.Net.Http;
using System.Web.Http.Controllers;
namespace System.Web.Http.Routing
{
internal static class HttpRouteExtensions
{
// If route is a direct route, get the action descriptors, order and precedence it may map to.
public static CandidateAction[] GetDirectRouteCandidates(this IHttpRoute route)
{
Contract.Assert(route != null);
IDictionary<string, object> dataTokens = route.DataTokens;
if (dataTokens == null)
{
return null;
}
List<CandidateAction> candidates = new List<CandidateAction>();
HttpActionDescriptor[] directRouteActions = null;
HttpActionDescriptor[] possibleDirectRouteActions;
if (dataTokens.TryGetValue<HttpActionDescriptor[]>(RouteDataTokenKeys.Actions, out possibleDirectRouteActions))
{
if (possibleDirectRouteActions != null && possibleDirectRouteActions.Length > 0)
{
directRouteActions = possibleDirectRouteActions;
}
}
if (directRouteActions == null)
{
return null;
}
int order = 0;
int possibleOrder;
if (dataTokens.TryGetValue<int>(RouteDataTokenKeys.Order, out possibleOrder))
{
order = possibleOrder;
}
decimal precedence = 0M;
decimal possiblePrecedence;
if (dataTokens.TryGetValue<decimal>(RouteDataTokenKeys.Precedence, out possiblePrecedence))
{
precedence = possiblePrecedence;
}
foreach (HttpActionDescriptor actionDescriptor in directRouteActions)
{
candidates.Add(new CandidateAction
{
ActionDescriptor = actionDescriptor,
Order = order,
Precedence = precedence
});
}
return candidates.ToArray();
}
public static HttpActionDescriptor[] GetTargetActionDescriptors(this IHttpRoute route)
{
Contract.Assert(route != null);
IDictionary<string, object> dataTokens = route.DataTokens;
if (dataTokens == null)
{
return null;
}
HttpActionDescriptor[] actions;
if (!dataTokens.TryGetValue<HttpActionDescriptor[]>(RouteDataTokenKeys.Actions, out actions))
{
return null;
}
return actions;
}
public static HttpControllerDescriptor GetTargetControllerDescriptor(this IHttpRoute route)
{
Contract.Assert(route != null);
IDictionary<string, object> dataTokens = route.DataTokens;
if (dataTokens == null)
{
return null;
}
HttpControllerDescriptor controller;
if (!dataTokens.TryGetValue<HttpControllerDescriptor>(RouteDataTokenKeys.Controller, out controller))
{
return null;
}
return controller;
}
}
}