public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider) { string routeName = null; RouteValueDictionary routeValues = new RouteValueDictionary(); if (RouteUrlExpressionBuilder.TryParseRouteExpression(expression, routeValues, out routeName)) { return("RouteUrl: " + expression); } return(System.Design.SR.GetString("RouteUrlExpressionEditor_InvalidExpression")); }
public RouteUrlExpressionEditorSheet(string expression, IServiceProvider serviceProvider) : base(serviceProvider) { if (!string.IsNullOrEmpty(expression)) { string routeName = null; RouteValueDictionary routeValues = new RouteValueDictionary(); if (RouteUrlExpressionBuilder.TryParseRouteExpression(expression, routeValues, out routeName)) { this.RouteName = routeName; StringBuilder builder = new StringBuilder(); foreach (string str2 in routeValues.Keys) { if (builder.Length > 0) { builder.Append(","); } builder.Append(str2).Append("=").Append(routeValues[str2]); } this.RouteValues = builder.ToString(); } } }
public void TryParseRouteExpression() { string routeName; var rvd = new RouteValueDictionary(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression(null, rvd, out routeName), "#A1-1"); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression(String.Empty, rvd, out routeName), "#A1-2"); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("route", rvd, out routeName), "#A1-3"); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression("route=", rvd, out routeName), "#A1-4"); Assert.AreEqual(1, rvd.Count, "#A1-4-1"); Assert.AreEqual(String.Empty, rvd ["route"], "#A1-4-2"); AssertExtensions.Throws <NullReferenceException> (() => { RouteUrlExpressionBuilder.TryParseRouteExpression("foo=bar", null, out routeName); }, "#A1-5"); rvd.Clear(); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression("foo=bar", rvd, out routeName), "#A2-1"); Assert.AreEqual(1, rvd.Count, "#A2-2"); Assert.AreEqual("bar", rvd ["foo"], "#A2-3"); Assert.IsNull(routeName, "#A2-4"); rvd.Clear(); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression("routeName=route,foo=bar,baz=zonk", rvd, out routeName), "#A3-1"); Assert.AreEqual(2, rvd.Count, "#A3-2"); Assert.AreEqual("bar", rvd ["foo"], "#A3-3"); Assert.AreEqual("zonk", rvd ["baz"], "#A3-3"); Assert.IsNotNull(routeName, "#A3-5"); Assert.AreEqual("route", routeName, "#A3-6"); rvd.Clear(); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression(" rOUteName=route , foo=bar\t, baz =\t zonk \t ", rvd, out routeName), "#A4-1"); Assert.AreEqual(2, rvd.Count, "#A4-2"); Assert.AreEqual("bar", rvd ["foo"], "#A4-3"); Assert.AreEqual("zonk", rvd ["baz"], "#A4-3"); Assert.IsNotNull(routeName, "#A4-5"); Assert.AreEqual("route", routeName, "#A4-6"); rvd.Clear(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("foo=bar,route,baz=zonk", rvd, out routeName), "#A5-1"); Assert.AreEqual(1, rvd.Count, "#A5-2"); Assert.AreEqual("bar", rvd ["foo"], "#A5-3"); rvd.Clear(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("foo=bar,route==,baz=zonk", rvd, out routeName), "#A6-1"); Assert.AreEqual(1, rvd.Count, "#A6-2"); Assert.AreEqual("bar", rvd ["foo"], "#A6-3"); rvd.Clear(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("route==", rvd, out routeName), "#A7-1"); Assert.AreEqual(0, rvd.Count, "#A7-2"); rvd.Clear(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("route==stuff", rvd, out routeName), "#A8-1"); Assert.AreEqual(0, rvd.Count, "#A8-2"); rvd.Clear(); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression("route=stuff1,route=stuff2", rvd, out routeName), "#A9-1"); Assert.AreEqual(1, rvd.Count, "#A9-2"); Assert.AreEqual("stuff2", rvd ["route"], "#A9-3"); rvd.Clear(); Assert.IsFalse(RouteUrlExpressionBuilder.TryParseRouteExpression("=stuff", rvd, out routeName), "#A10-1"); Assert.AreEqual(0, rvd.Count, "#A10-2"); rvd.Clear(); Assert.IsTrue(RouteUrlExpressionBuilder.TryParseRouteExpression("routeName=route,routename=route2,foo=bar,baz=zonk", rvd, out routeName), "#A11-1"); Assert.AreEqual(2, rvd.Count, "#A11-2"); Assert.AreEqual("bar", rvd ["foo"], "#A11-3"); Assert.AreEqual("zonk", rvd ["baz"], "#A11-3"); Assert.IsNotNull(routeName, "#A11-5"); Assert.AreEqual("route2", routeName, "#A11-6"); }