当前位置: 首页>>代码示例>>C#>>正文


C# RouteCollection.OfType方法代码示例

本文整理汇总了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"]);
        }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:19,代码来源:HttpRouteTableBuilderTests.cs

示例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")));
        }
开发者ID:rafaelmtz,项目名称:azure-webjobs-sdk,代码行数:15,代码来源:RouteConfig.cs

示例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;
 }
开发者ID:OnesAndTwos,项目名称:Web,代码行数:15,代码来源:NavigationExtensions.cs

示例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;
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:16,代码来源:ScriptRouteTableProvider.cs

示例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"));
        }
开发者ID:erik-kallen,项目名称:NuGetServer,代码行数:18,代码来源:ApplicationBootstrapper.cs

示例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;
 }
开发者ID:davidalpert,项目名称:twitter.bootstrap.mvc,代码行数:19,代码来源:NavigationExtensions.cs

示例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");
                }
            }
        }
开发者ID:xuanvu,项目名称:SymbolSource.Community,代码行数:21,代码来源:AttributeRouting.cs

示例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;
        }
开发者ID:ritacc,项目名称:RitaccTest,代码行数:33,代码来源:DefaultControllerTypeResolver.cs

示例9: GetAttributeRoutes

 private IReadOnlyCollection<RouteBase> GetAttributeRoutes(RouteCollection routes)
 {
     return routes.OfType<IReadOnlyCollection<RouteBase>>().Single();
 }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:4,代码来源:RouteCollectionAttributeRoutingExtensionsTests.cs

示例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>");
        }
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:51,代码来源:RouteDebugHandler.cs

示例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();
 }
开发者ID:Nagelfar,项目名称:FeatureController,代码行数:10,代码来源:FeatureBundles.cs


注:本文中的RouteCollection.OfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。