CR feedback again
This commit is contained in:
parent
f43985b58d
commit
f604fb8d87
|
|
@ -21,10 +21,11 @@ namespace RoutingSample
|
|||
context.IsHandled = true;
|
||||
}
|
||||
|
||||
public void BindPath(BindPathContext context)
|
||||
public string BindPath(BindPathContext context)
|
||||
{
|
||||
// We can generate a url for anything that the parent route deems OK.
|
||||
// We don't really care what the values look like.
|
||||
context.IsBound = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ namespace RoutingSample
|
|||
}
|
||||
}
|
||||
|
||||
public void BindPath(BindPathContext context)
|
||||
public string BindPath(BindPathContext context)
|
||||
{
|
||||
// Do nothing
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ namespace Microsoft.AspNet.Routing
|
|||
|
||||
public bool IsBound { get; set; }
|
||||
|
||||
public string BoundPath { get; set; }
|
||||
|
||||
public IDictionary<string, object> Values { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ namespace Microsoft.AspNet.Routing
|
|||
{
|
||||
Task RouteAsync(RouteContext context);
|
||||
|
||||
void BindPath(BindPathContext context);
|
||||
string BindPath(BindPathContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
|
|
@ -41,18 +40,20 @@ namespace Microsoft.AspNet.Routing
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void BindPath(BindPathContext context)
|
||||
public virtual string BindPath(BindPathContext context)
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
var route = this[i];
|
||||
|
||||
route.BindPath(context);
|
||||
if (context.IsBound)
|
||||
var path = route.BindPath(context);
|
||||
if (path != null)
|
||||
{
|
||||
return;
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,28 +75,29 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
}
|
||||
}
|
||||
|
||||
public void BindPath(BindPathContext context)
|
||||
public string BindPath(BindPathContext context)
|
||||
{
|
||||
// Validate that the target can accept these values.
|
||||
_target.BindPath(context);
|
||||
if (!context.IsBound)
|
||||
// Validate that the target can accept these values - if the target generates a value
|
||||
// then that can short circuit.
|
||||
var path = _target.BindPath(context);
|
||||
if (path != null)
|
||||
{
|
||||
return;
|
||||
return path;
|
||||
}
|
||||
else if (!context.IsBound)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// This could be optimized more heavily - right now we try to do the full url
|
||||
// generation after validating, but we could do it in two phases.
|
||||
var path = _binder.Bind(_defaults, context.AmbientValues, context.Values);
|
||||
path = _binder.Bind(_defaults, context.AmbientValues, context.Values);
|
||||
if (path == null)
|
||||
{
|
||||
context.IsBound = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Assert(context.IsBound);
|
||||
context.BoundPath = path;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,11 +113,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
var context = CreateRouteBindContext(new {controller = "Home"});
|
||||
|
||||
// Act
|
||||
route.BindPath(context);
|
||||
var path = route.BindPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
Assert.Equal("Home", context.BoundPath);
|
||||
Assert.Equal("Home", path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -128,11 +128,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
var context = CreateRouteBindContext(new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
route.BindPath(context);
|
||||
var path = route.BindPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
Assert.Null(context.BoundPath);
|
||||
Assert.Null(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -143,11 +143,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
var context = CreateRouteBindContext(new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
route.BindPath(context);
|
||||
var path = route.BindPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
Assert.Null(context.BoundPath);
|
||||
Assert.Null(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -158,11 +158,11 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
var context = CreateRouteBindContext(new { action = "Index"}, new { controller = "Home" });
|
||||
|
||||
// Act
|
||||
route.BindPath(context);
|
||||
var path = route.BindPath(context);
|
||||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
Assert.Equal("Home/Index", context.BoundPath);
|
||||
Assert.Equal("Home/Index", path);
|
||||
}
|
||||
|
||||
private static BindPathContext CreateRouteBindContext(object values)
|
||||
|
|
|
|||
Loading…
Reference in New Issue