Upravit

Sdílet prostřednictvím


UriTemplate.BindByPosition(Uri, String[]) Method

Definition

Creates a new URI from the template and an array of parameter values.

public:
 Uri ^ BindByPosition(Uri ^ baseAddress, ... cli::array <System::String ^> ^ values);
public Uri BindByPosition (Uri baseAddress, params string[] values);
member this.BindByPosition : Uri * string[] -> Uri
Public Function BindByPosition (baseAddress As Uri, ParamArray values As String()) As Uri

Parameters

baseAddress
Uri

A Uri that contains the base address.

values
String[]

The parameter values.

Returns

Uri

A new Uri instance.

Examples

The following example shows how to call the BindByPosition(Uri, String[]).

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

Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond", "Today");
Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")

Dim positionalUri As Uri = template.BindByPosition(prefix, "Washington", "Redmond", "Today")

Remarks

The parameter values are bound by position left to right. The first parameter value replaces the first variable found in the template, the second parameter value replaces the second variable, and so on. Variables passed to this method are escaped.

Note

The number of parameters passed in the values parameter must match the number of variables in the template. If not, a FormatException is thrown.

Note

It is possible to pass in text within the parameter values array that prevents the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '.','..', '*', '{', and '}'. The following code demonstrates this.

UriTemplate template = new UriTemplate("far/{bat}/baz");

Uri uri = new Uri("http://localhost/Base");

Uri result = template.BindByPosition(uri, "."); // returns Base/form/baz

Uri result = template.BindByPosition(uri, ".."); // returns Base/baz

Uri result = template.BindByPosition(uri, "x/y"); // returns Base/form/x/y/baz

Uri result = template.BindByPosition(uri, "{x}"); // returns Base/form/{x}/baz

Uri result = template.BindByPosition(uri, "*"); // returns Base/form/*/baz

Applies to