Edit

Share via


UriTemplate.BindByName Method

Definition

Creates a new URI from the template and the collection of parameters.

Overloads

BindByName(Uri, IDictionary<String,String>)

Creates a new URI from the template and the collection of parameters.

BindByName(Uri, NameValueCollection)

Creates a new URI from the template and the collection of parameters.

BindByName(Uri, IDictionary<String,String>, Boolean)

Creates a new URI from the template and the collection of parameters.

BindByName(Uri, NameValueCollection, Boolean)

Creates a new URI from the template and the collection of parameters.

BindByName(Uri, IDictionary<String,String>)

Creates a new URI from the template and the collection of parameters.

C#
public Uri BindByName(Uri baseAddress, System.Collections.Generic.IDictionary<string,string> parameters);

Parameters

baseAddress
Uri

The base address.

parameters
IDictionary<String,String>

A dictionary that contains a collection of parameter name/value pairs.

Returns

Uri

A URI.

Remarks

The IDictionary<string,string> parameter contains a collection of parameter name and value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison.

Note

The name/value collection passed to this method must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI.

Important

It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BindByName(Uri, NameValueCollection)

Creates a new URI from the template and the collection of parameters.

C#
public Uri BindByName(Uri baseAddress, System.Collections.Specialized.NameValueCollection parameters);

Parameters

baseAddress
Uri

The base address.

parameters
NameValueCollection

The parameter values.

Returns

Uri

A new instance.

Examples

The following example shows how to call the BindByName(Uri, NameValueCollection) method.

C#
UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast={day}");
Uri prefix = new Uri("http://localhost");

NameValueCollection parameters = new NameValueCollection();
parameters.Add("state", "Washington");
parameters.Add("city", "Redmond");
parameters.Add("day", "Today");
Uri namedUri = template.BindByName(prefix, parameters);

Remarks

The NameValueCollection parameter contains a collection of parameter name/value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. Values passed in this collection are escaped.

Note

The name/value collection passed to BindByName(Uri, NameValueCollection) must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI.

Note

It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BindByName(Uri, IDictionary<String,String>, Boolean)

Creates a new URI from the template and the collection of parameters.

C#
public Uri BindByName(Uri baseAddress, System.Collections.Generic.IDictionary<string,string> parameters, bool omitDefaults);

Parameters

baseAddress
Uri

A URI that contains the base address.

parameters
IDictionary<String,String>

A dictionary that contains a collection of parameter name/value pairs.

omitDefaults
Boolean

true is the default values are ignored; otherwise false.

Returns

Uri

A URI.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

BindByName(Uri, NameValueCollection, Boolean)

Creates a new URI from the template and the collection of parameters.

C#
public Uri BindByName(Uri baseAddress, System.Collections.Specialized.NameValueCollection parameters, bool omitDefaults);

Parameters

baseAddress
Uri

The base address.

parameters
NameValueCollection

A collection of parameter name/value pairs.

omitDefaults
Boolean

true if the default values are ignored; otherwise false.

Returns

Uri

A URI.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1