UriTemplate.BindByPosition(Uri, String[]) UriTemplate.BindByPosition(Uri, String[]) UriTemplate.BindByPosition(Uri, String[]) UriTemplate.BindByPosition(Uri, String[]) Method

定义

Creates a new URI from the template and an array of parameter values.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

参数

baseAddress
Uri Uri Uri Uri

A Uri that contains the base address.A Uri that contains the base address.

values
String[]

The parameter values.The parameter values.

返回

A new Uri instance.A new Uri instance.

示例

下面的示例演示如何调用 BindByPosition(Uri, String[])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")

注解

参数值按位置从左至右绑定。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.

备注

传入值参数的参数个数必须与模板中的变量个数相符。The number of parameters passed in the values parameter must match the number of variables in the template. 如果不符,则会引发 FormatExceptionIf not, a FormatException is thrown.

备注

您可以在参数值数组中传入文本,以阻止生成的 URI 与用于生成它的模板匹配。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

适用于