本文整理汇总了C#中RouteCollection.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.OfType方法的具体用法?C# RouteCollection.OfType怎么用?C# RouteCollection.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.OfType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBuildHttpRouteTable
public void TestBuildHttpRouteTable()
{
var routes = new RouteCollection();
HttpRouteTableBuilder.BuildTable(routes,typeof(HttpRouteTableBuilderTests).Assembly);
// Check that the HTTP route table is build correctly
Assert.AreEqual(3,routes.Count);
Assert.IsTrue(routes.OfType<HttpWebRoute>().Any(route => route.Url == "api/methodlevel/route/{id}"));
Assert.IsTrue(routes.OfType<HttpWebRoute>().Any(route => route.Url == "api/subroute/controller"));
Assert.IsTrue(routes.OfType<HttpWebRoute>().Any(route => route.Url == "api/methodlevel/basic"));
// Find the route with optional url parameters
var routeWithParameters = routes.OfType<HttpWebRoute>()
.FirstOrDefault(route => route.Url == "api/methodlevel/route/{id}");
// Check that the ID parameter is indeed marked as optional.
Assert.IsNotNull(routeWithParameters);
Assert.AreEqual(RouteParameter.Optional, routeWithParameters.Defaults["id"]);
}
示例2: RegisterNoAccountRoutes
public static void RegisterNoAccountRoutes(RouteCollection routes)
{
if (routes == null)
{
throw new ArgumentNullException("routes");
}
RegisterRoutes(routes);
// deregister the non SPA MVC route, and replace it with a redirect to Functions Homepage so
// the user would get the helpful error.
var legacyRoute = routes.OfType<Route>().First(r => r.Url == FunctionController.LegacyNonSpaRouteUrl);
routes.Remove(legacyRoute);
routes.Add(new Route(FunctionController.LegacyNonSpaRouteUrl, new RedirectRouteHandler("~/#/functions")));
}
示例3: GetRoutesForCurrentRequest
public static IEnumerable<NamedRoute> GetRoutesForCurrentRequest(RouteCollection routes,IEnumerable<INavigationRouteFilter> routeFilters)
{
var navigationRoutes = routes.OfType<NamedRoute>().Where(r=> !r.IsChild).ToList();
if (routeFilters.Any())
{
foreach (var route in navigationRoutes.ToArray())
{
if (routeFilters.Any(filter => filter.ShouldRemove(route)))
{
navigationRoutes.Remove(route);
}
}
}
return navigationRoutes;
}
示例4: GetRouteTable
public IEnumerable<RouteDefinition> GetRouteTable(RouteCollection routes)
{
List<RouteDefinition> collection = new List<RouteDefinition>();
RouteReader reader = CreateReader(new IRouteInterceptor[] {
new RegexConstraintReader(),
new RouteVariableAssigner(routes.Variables)
});
foreach (Route route in routes.OfType<Route>())
{
RouteDefinition definition = reader.Read(route);
if (definition != null)
collection.Add(definition);
}
return collection;
}
示例5: MapRoutes
private static void MapRoutes(RouteCollection routes)
{
// The default route is http://{root}/nuget/Packages
var factory = new DataServiceHostFactory();
var serviceRoute = new ServiceRoute("nuget", factory, typeof(Packages));
serviceRoute.Defaults = new RouteValueDictionary { { "serviceType", "odata" } };
serviceRoute.Constraints = new RouteValueDictionary { { "serviceType", "odata" } };
routes.Add("nuget", serviceRoute);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
// For some godforsaken reason, the PublishPackage route (registered by NuGet.Server) causes the { controller, action } => url mapping to always return this route.
routes.Remove(routes.OfType<Route>().Single(r => r.DataTokens != null && r.DataTokens.ContainsKey("__RouteName") && (string)r.DataTokens["__RouteName"] == "PublishPackage"));
}
示例6: GetRoutesForCurrentRequest
public static IEnumerable<NamedRoute> GetRoutesForCurrentRequest(RouteCollection routes,IEnumerable<INavigationRouteFilter> routeFilters)
{
var navigationRoutes = routes.OfType<NamedRoute>().ToList();
if (routeFilters.Count() > 0)
{
foreach (var route in navigationRoutes.ToArray())
{
foreach (var filter in routeFilters)
{
if (filter.ShouldRemove(route))
{
navigationRoutes.Remove(route);
break;
}
}
}
}
return navigationRoutes;
}
示例7: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
//routes.MapAttributeRoutes();
foreach (var route in routes.OfType<Route>())
{
if(route.DataTokens == null)
continue;
var namespaces = route.DataTokens["namespaces"] as string[];
if (namespaces != null)
{
route.Url = Regex.Match(namespaces[0], "^SymbolSource.Gateway.([^.]+).Core$").Groups[1] + "/" + route.Url;
ReplaceToken(route, "login", "Basic");
ReplaceToken(route, "company", "Basic");
ReplaceToken(route, "password", "Basic");
ReplaceToken(route, "repository", "Basic");
}
}
}
示例8: FindNamespacesForArea
/// <summary>
/// Finds the namespaces for area.
/// </summary>
/// <param name="area">The area.</param>
/// <param name="routes">The routes.</param>
/// <returns>
/// A namespaces for area represented as a <see cref="string"/> instance
/// </returns>
protected IEnumerable<string> FindNamespacesForArea(string area, RouteCollection routes)
{
var namespacesForArea = new List<string>();
var namespacesCommon = new List<string>();
foreach (var route in routes.OfType<Route>().Where(r => r.DataTokens != null && r.DataTokens["Namespaces"] != null))
{
// search for area-based namespaces
if (route.DataTokens["area"] != null && route.DataTokens["area"].ToString().Equals(area, StringComparison.OrdinalIgnoreCase))
namespacesForArea.AddRange((IEnumerable<string>)route.DataTokens["Namespaces"]);
else if (route.DataTokens["area"] == null)
namespacesCommon.AddRange((IEnumerable<string>)route.DataTokens["Namespaces"]);
}
if (namespacesForArea.Count > 0)
{
return namespacesForArea;
}
else if (namespacesCommon.Count > 0)
{
return namespacesCommon;
}
return null;
}
示例9: GetAttributeRoutes
private IReadOnlyCollection<RouteBase> GetAttributeRoutes(RouteCollection routes)
{
return routes.OfType<IReadOnlyCollection<RouteBase>>().Single();
}
示例10: RenderRoutesVB
void RenderRoutesVB(RouteCollection routes)
{
if (routes == null) throw new ArgumentNullException("routes");
writer.Write("<!DOCTYPE html>");
writer.Write("<html>");
RenderHtmlHead();
writer.Write("<body class='vb'>");
RenderTopComments("'");
writer.WriteLine();
string prevRouteContext = null;
foreach (Route route in routes.OfType<Route>()) {
string routeContext = (route.DataTokens != null) ?
route.DataTokens[DataTokenKeys.RouteContext] as string
: null;
if (routeContext != prevRouteContext) {
if (prevRouteContext != null) {
writer.WriteLine();
writer.WriteLine("<span class='keyword'>#End Region</span>");
}
if (routeContext != null) {
string display = routeContext.Length == 0 ? "(root)" : routeContext;
writer.WriteLine();
writer.Write("<span class='keyword'>#Region</span> ");
writer.Write(ValueToVBString(display));
writer.WriteLine();
}
}
writer.WriteLine();
RenderRouteVB(route);
prevRouteContext = routeContext;
}
if (prevRouteContext != null) {
writer.WriteLine();
writer.Write("<span class='keyword'>#End Region</span>");
}
writer.Write("</body>");
writer.Write("</html>");
}
示例11: GetAreaNameAndNamespace
private static IEnumerable<Tuple<string, string>> GetAreaNameAndNamespace(RouteCollection routeEntries)
{
var areas = routeEntries
.OfType<Route>()
.Where(x => x.DataTokens != null)
.Where(x => x.DataTokens.Any(token => token.Key == "area"))
.Select(x => Tuple.Create(ExtractSingleValue(x.DataTokens["area"]), ExtractSingleValue(x.DataTokens["Namespaces"]).Replace("*", "").TrimEnd('.')))
;
return areas.ToArray();
}