You've already forked linux-packaging-mono
69 lines
3.1 KiB
C#
69 lines
3.1 KiB
C#
![]() |
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
|
|||
|
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Web.Http.WebHost;
|
|||
|
using System.Web.Http.WebHost.Routing;
|
|||
|
using System.Web.Routing;
|
|||
|
|
|||
|
namespace System.Web.Http
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Extension methods for <see cref="RouteCollection"/>
|
|||
|
/// </summary>
|
|||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|||
|
public static class RouteCollectionExtensions
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Maps the specified route template.
|
|||
|
/// </summary>
|
|||
|
/// <param name="routes">A collection of routes for the application.</param>
|
|||
|
/// <param name="name">The name of the route to map.</param>
|
|||
|
/// <param name="routeTemplate">The route template for the route.</param>
|
|||
|
/// <returns>A reference to the mapped route.</returns>
|
|||
|
public static Route MapHttpRoute(this RouteCollection routes, string name, string routeTemplate)
|
|||
|
{
|
|||
|
return MapHttpRoute(routes, name, routeTemplate, defaults: null, constraints: null);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Maps the specified route template and sets default constraints, and namespaces.
|
|||
|
/// </summary>
|
|||
|
/// <param name="routes">A collection of routes for the application.</param>
|
|||
|
/// <param name="name">The name of the route to map.</param>
|
|||
|
/// <param name="routeTemplate">The route template for the route.</param>
|
|||
|
/// <param name="defaults">An object that contains default route values.</param>
|
|||
|
/// <returns>A reference to the mapped route.</returns>
|
|||
|
public static Route MapHttpRoute(this RouteCollection routes, string name, string routeTemplate, object defaults)
|
|||
|
{
|
|||
|
return MapHttpRoute(routes, name, routeTemplate, defaults, constraints: null);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Maps the specified route template and sets default route values, constraints, and namespaces.
|
|||
|
/// </summary>
|
|||
|
/// <param name="routes">A collection of routes for the application.</param>
|
|||
|
/// <param name="name">The name of the route to map.</param>
|
|||
|
/// <param name="routeTemplate">The route template for the route.</param>
|
|||
|
/// <param name="defaults">An object that contains default route values.</param>
|
|||
|
/// <param name="constraints">A set of expressions that specify values for <paramref name="routeTemplate"/>.</param>
|
|||
|
/// <returns>A reference to the mapped route.</returns>
|
|||
|
public static Route MapHttpRoute(this RouteCollection routes, string name, string routeTemplate, object defaults, object constraints)
|
|||
|
{
|
|||
|
if (routes == null)
|
|||
|
{
|
|||
|
throw Error.ArgumentNull("routes");
|
|||
|
}
|
|||
|
|
|||
|
HttpWebRoute route = new HttpWebRoute(routeTemplate, HttpControllerRouteHandler.Instance)
|
|||
|
{
|
|||
|
Defaults = new RouteValueDictionary(defaults),
|
|||
|
Constraints = new RouteValueDictionary(constraints),
|
|||
|
DataTokens = new RouteValueDictionary()
|
|||
|
};
|
|||
|
|
|||
|
routes.Add(name, route);
|
|||
|
return route;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|