This commit is contained in:
Ryan Nowak 2014-10-31 15:02:54 -07:00
parent d78e5478a7
commit aae9e67773
2 changed files with 32 additions and 13 deletions

View File

@ -6,8 +6,14 @@ using System.Collections.Generic;
namespace Microsoft.AspNet.Routing
{
/// <summary>
/// Information about the current routing path.
/// </summary>
public class RouteData
{
/// <summary>
/// Creates a new <see cref="RouteData"/> instance.
/// </summary>
public RouteData()
{
DataTokens = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
@ -15,6 +21,10 @@ namespace Microsoft.AspNet.Routing
Values = new RouteValueDictionary();
}
/// <summary>
/// Creates a new <see cref="RouteData"/> instance with values copied from <paramref name="other"/>.
/// </summary>
/// <param name="other">The other <see cref="RouteData"/> instance to copy.</param>
public RouteData([NotNull] RouteData other)
{
DataTokens = new Dictionary<string, object>(other.DataTokens, StringComparer.OrdinalIgnoreCase);
@ -22,10 +32,19 @@ namespace Microsoft.AspNet.Routing
Values = new RouteValueDictionary(other.Values);
}
/// <summary>
/// Gets the data tokens produced by routes on the current routing path.
/// </summary>
public IDictionary<string, object> DataTokens { get; private set; }
/// <summary>
/// Gets the list of <see cref="IRouter"/> instances on the current routing path.
/// </summary>
public List<IRouter> Routers { get; private set; }
/// <summary>
/// Gets the set of values produced by routes on the current routing path.
/// </summary>
public IDictionary<string, object> Values { get; private set; }
public IDictionary<string, object> DataTokens { get; private set; }
}
}

View File

@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Routing.Template
{
_logger.WriteValues(CreateRouteAsyncValues(
requestPath,
values,
context.RouteData.Values,
matchedValues: false,
matchedConstraints: false,
handled: context.IsHandled));
@ -121,9 +121,16 @@ namespace Microsoft.AspNet.Routing.Template
return;
}
var oldRouteData = context.RouteData;
var newRouteData = new RouteData(oldRouteData);
MergeValues(newRouteData.DataTokens, _dataTokens);
newRouteData.Routers.Add(_target);
MergeValues(newRouteData.Values, values);
if (!RouteConstraintMatcher.Match(
Constraints,
values,
newRouteData.Values,
context.HttpContext,
this,
RouteDirection.IncomingRequest,
@ -133,7 +140,7 @@ namespace Microsoft.AspNet.Routing.Template
{
_logger.WriteValues(CreateRouteAsyncValues(
requestPath,
values,
newRouteData.Values,
matchedValues: true,
matchedConstraints: false,
handled: context.IsHandled));
@ -142,13 +149,6 @@ namespace Microsoft.AspNet.Routing.Template
return;
}
var oldRouteData = context.RouteData;
var newRouteData = new RouteData(oldRouteData);
MergeValues(newRouteData.DataTokens, _dataTokens);
newRouteData.Routers.Add(_target);
MergeValues(newRouteData.Values, values);
try
{
context.RouteData = newRouteData;
@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Routing.Template
{
_logger.WriteValues(CreateRouteAsyncValues(
requestPath,
values,
newRouteData.Values,
matchedValues: true,
matchedConstraints: true,
handled: context.IsHandled));