public virtual VirtualPathData GetVirtualPath(VirtualPathContext context) { var values = _binder.GetValues(context.AmbientValues, context.Values); if (values == null) { // We're missing one of the required values for this route. return(null); } EnsureLoggers(context.Context); if (!RouteConstraintMatcher.Match(Constraints, values.CombinedValues, context.Context, this, RouteDirection.UrlGeneration, _constraintLogger)) { return(null); } // Validate that the target can accept these values. var childContext = CreateChildVirtualPathContext(context, values.AcceptedValues); var pathData = _target.GetVirtualPath(childContext); if (pathData != null) { // If the target generates a value then that can short circuit. return(pathData); } // If we can produce a value go ahead and do it, the caller can check context.IsBound // to see if the values were validated. // When we still cannot produce a value, this should return null. var tempPath = _binder.BindValues(values.AcceptedValues); if (tempPath == null) { return(null); } pathData = new VirtualPathData(this, tempPath); if (DataTokens != null) { foreach (var dataToken in DataTokens) { pathData.DataTokens.Add(dataToken.Key, dataToken.Value); } } context.IsBound = childContext.IsBound; return(pathData); }
public virtual string GetVirtualPath(VirtualPathContext context) { var values = _binder.GetValues(context.AmbientValues, context.Values); if (values == null) { // We're missing one of the required values for this route. return(null); } EnsureLoggers(context.Context); if (!RouteConstraintMatcher.Match(Constraints, values.CombinedValues, context.Context, this, RouteDirection.UrlGeneration, _constraintLogger)) { return(null); } // Validate that the target can accept these values. var childContext = CreateChildVirtualPathContext(context, values.AcceptedValues); var path = _target.GetVirtualPath(childContext); if (path != null) { // If the target generates a value then that can short circuit. context.IsBound = true; return(path); } else if (!childContext.IsBound) { // The target has rejected these values. return(null); } path = _binder.BindValues(values.AcceptedValues); if (path != null) { context.IsBound = true; } return(path); }