// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.ComponentModel;
using System.Web.Http.Routing;
namespace System.Web.Http
{
///
/// Extension methods for
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpRouteCollectionExtensions
{
///
/// Maps the specified route template.
///
/// A collection of routes for the application.
/// The name of the route to map.
/// The route template for the route.
/// A reference to the mapped route.
public static IHttpRoute MapHttpRoute(this HttpRouteCollection routes, string name, string routeTemplate)
{
return MapHttpRoute(routes, name, routeTemplate, defaults: null, constraints: null);
}
///
/// Maps the specified route template and sets default constraints.
///
/// A collection of routes for the application.
/// The name of the route to map.
/// The route template for the route.
/// An object that contains default route values.
/// A reference to the mapped route.
public static IHttpRoute MapHttpRoute(this HttpRouteCollection routes, string name, string routeTemplate, object defaults)
{
return MapHttpRoute(routes, name, routeTemplate, defaults, constraints: null);
}
///
/// Maps the specified route template and sets default route values and constraints.
///
/// A collection of routes for the application.
/// The name of the route to map.
/// The route template for the route.
/// An object that contains default route values.
/// A set of expressions that specify values for .
/// A reference to the mapped route.
public static IHttpRoute MapHttpRoute(this HttpRouteCollection routes, string name, string routeTemplate, object defaults, object constraints)
{
if (routes == null)
{
throw Error.ArgumentNull("routes");
}
IHttpRoute route = routes.CreateRoute(routeTemplate, defaults, constraints, parameters: null);
routes.Add(name, route);
return route;
}
}
}