forked from haoduotnt/aspnetwebstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectRouteExtensions.cs
More file actions
63 lines (56 loc) · 1.93 KB
/
DirectRouteExtensions.cs
File metadata and controls
63 lines (56 loc) · 1.93 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
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
using System.Web.Routing;
namespace System.Web.Mvc.Routing
{
internal static class DirectRouteExtensions
{
private const string TargetActionMethodKey = "TargetActionMethod";
/// <summary>
/// Gets the target action method that will be invoked if this route is matched.
/// </summary>
public static MethodInfo GetTargetActionMethod(this RouteData routeData)
{
if (routeData == null)
{
throw Error.ArgumentNull("routeData");
}
Route route = routeData.Route as Route;
if (route == null)
{
return null;
}
return GetTargetActionMethod(route);
}
/// <summary>
/// Sets the target action method that will be invoked if this route is matched.
/// </summary>
public static void SetTargetActionMethod(this Route route, MethodInfo targetMethod)
{
if (route == null)
{
throw Error.ArgumentNull("route");
}
if (route.DataTokens == null)
{
route.DataTokens = new RouteValueDictionary();
}
route.DataTokens[TargetActionMethodKey] = targetMethod;
}
/// <summary>
/// Gets the target action method that will be invoked if this route is matched.
/// </summary>
internal static MethodInfo GetTargetActionMethod(this Route route)
{
if (route == null)
{
throw Error.ArgumentNull("route");
}
if (route.DataTokens == null)
{
return null;
}
return route.DataTokens[TargetActionMethodKey] as MethodInfo;
}
}
}