Export (0) Print
Expand All

UriTemplate.BindByPosition Method

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

Namespace:  System
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public Uri BindByPosition(
	Uri baseAddress,
	params string[] values
)

Parameters

baseAddress
Type: System.Uri
A Uri that contains the base address.
values
Type: System.String[]
The parameter values.

Return Value

Type: System.Uri
A new Uri instance.

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.

NoteNote

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

NoteNote

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

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");


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft