Table of Contents

Class HttpRouteCollection

Namespace
System.Web.Http
Assembly
System.Web.Http.dll

A collection of IHttpRoute instances.

public class HttpRouteCollection : ICollection<IHttpRoute>, IEnumerable<IHttpRoute>, IEnumerable, IDisposable
Inheritance
HttpRouteCollection
Implements
Inherited Members

Constructors

HttpRouteCollection()

Initializes a new instance of the HttpRouteCollection class.

public HttpRouteCollection()

HttpRouteCollection(string)

Initializes a new instance of the HttpRouteCollection class.

public HttpRouteCollection(string virtualPathRoot)

Parameters

virtualPathRoot string

The virtual path root.

Properties

Count

Gets the number of items in the collection.

public virtual int Count { get; }

Property Value

int

The number of items in the collection.

IsReadOnly

Gets a value indicating whether the collection is read-only.

public virtual bool IsReadOnly { get; }

Property Value

bool

true if the collection is read-only; otherwise, false.

this[int]

Gets or sets the element at the specified index.

public virtual IHttpRoute this[int index] { get; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

IHttpRoute

The IHttpRoute at the specified index.

this[string]

Gets or sets the element with the specified route name.

public virtual IHttpRoute this[string name] { get; }

Parameters

name string

The route name.

Property Value

IHttpRoute

The IHttpRoute at the specified index.

VirtualPathRoot

Gets the virtual path root.

public virtual string VirtualPathRoot { get; }

Property Value

string

The virtual path root.

Methods

Add(string, IHttpRoute)

Adds an IHttpRoute instance to the collection.

public virtual void Add(string name, IHttpRoute route)

Parameters

name string

The name of the route.

route IHttpRoute

The IHttpRoute instance to add to the collection.

Clear()

Removes all items from the collection.

public virtual void Clear()

Contains(IHttpRoute)

Determines whether the collection contains a specific IHttpRoute.

public virtual bool Contains(IHttpRoute item)

Parameters

item IHttpRoute

The object to locate in the collection.

Returns

bool

true if the IHttpRoute is found in the collection; otherwise, false.

ContainsKey(string)

Determines whether the collection contains an element with the specified key.

public virtual bool ContainsKey(string name)

Parameters

name string

The key to locate in the collection.

Returns

bool

true if the collection contains an element with the key; otherwise, false.

CopyTo(KeyValuePair<string, IHttpRoute>[], int)

Copies the IHttpRoute instances of the collection to an array, starting at a particular array index.

public virtual void CopyTo(KeyValuePair<string, IHttpRoute>[] array, int arrayIndex)

Parameters

array KeyValuePair<string, IHttpRoute>[]

The array that is the destination of the elements copied from the collection.

arrayIndex int

The zero-based index in array at which copying begins.

CopyTo(IHttpRoute[], int)

Copies the route names and IHttpRoute instances of the collection to an array, starting at a particular array index.

public virtual void CopyTo(IHttpRoute[] array, int arrayIndex)

Parameters

array IHttpRoute[]

The array that is the destination of the elements copied from the collection.

arrayIndex int

The zero-based index in array at which copying begins.

CreateRoute(string, IDictionary<string, object>, IDictionary<string, object>, IDictionary<string, object>)

Creates an IHttpRoute instance.

public IHttpRoute CreateRoute(string routeTemplate, IDictionary<string, object> defaults, IDictionary<string, object> constraints, IDictionary<string, object> dataTokens)

Parameters

routeTemplate string

The route template.

defaults IDictionary<string, object>

An object that contains the default route parameters.

constraints IDictionary<string, object>

An object that contains the route constraints.

dataTokens IDictionary<string, object>

The route data tokens.

Returns

IHttpRoute

The new IHttpRoute instance.

CreateRoute(string, IDictionary<string, object>, IDictionary<string, object>, IDictionary<string, object>, HttpMessageHandler)

Creates an IHttpRoute instance.

public virtual IHttpRoute CreateRoute(string routeTemplate, IDictionary<string, object> defaults, IDictionary<string, object> constraints, IDictionary<string, object> dataTokens, HttpMessageHandler handler)

Parameters

routeTemplate string

The route template.

defaults IDictionary<string, object>

An object that contains the default route parameters.

constraints IDictionary<string, object>

An object that contains the route constraints.

dataTokens IDictionary<string, object>

The route data tokens.

handler HttpMessageHandler

The message handler for the route.

Returns

IHttpRoute

The new IHttpRoute instance.

CreateRoute(string, object, object)

Creates an IHttpRoute instance.

public IHttpRoute CreateRoute(string routeTemplate, object defaults, object constraints)

Parameters

routeTemplate string

The route template.

defaults object

An object that contains the default route parameters.

constraints object

An object that contains the route constraints.

Returns

IHttpRoute

The new IHttpRoute instance.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources that are used by the object and, optionally, releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public virtual IEnumerator<IHttpRoute> GetEnumerator()

Returns

IEnumerator<IHttpRoute>

An IEnumerator<T> that can be used to iterate through the collection.

GetRouteData(HttpRequestMessage)

Gets the route data for a specified HTTP request.

public virtual IHttpRouteData GetRouteData(HttpRequestMessage request)

Parameters

request HttpRequestMessage

The HTTP request.

Returns

IHttpRouteData

AnIHttpRouteData instance that represents the route data.

GetVirtualPath(HttpRequestMessage, string, IDictionary<string, object>)

Gets a virtual path.

public virtual IHttpVirtualPathData GetVirtualPath(HttpRequestMessage request, string name, IDictionary<string, object> values)

Parameters

request HttpRequestMessage

The HTTP request.

name string

The route name.

values IDictionary<string, object>

The route values.

Returns

IHttpVirtualPathData

An IHttpVirtualPathData instance that represents the virtual path.

Insert(int, string, IHttpRoute)

Inserts an IHttpRoute instance into the collection.

public virtual void Insert(int index, string name, IHttpRoute value)

Parameters

index int

The zero-based index at which value should be inserted.

name string

The route name.

value IHttpRoute

The IHttpRoute to insert. The value cannot be null.

OnGetEnumerator()

Called internally to get the enumerator for the collection.

protected virtual IEnumerator OnGetEnumerator()

Returns

IEnumerator

An IEnumerator that can be used to iterate through the collection.

Remove(string)

Removes an IHttpRoute instance from the collection.

public virtual bool Remove(string name)

Parameters

name string

The name of the route to remove.

Returns

bool

true if the element is successfully removed; otherwise, false. This method also returns false if name was not found in the collection.

TryGetValue(string, out IHttpRoute)

Gets the IHttpRoute with the specified route name.

public virtual bool TryGetValue(string name, out IHttpRoute route)

Parameters

name string

The route name.

route IHttpRoute

When this method returns, contains the IHttpRoute instance, if the route name is found; otherwise, null. This parameter is passed uninitialized.

Returns

bool

true if the collection contains an element with the specified name; otherwise, false.