UriTemplate.BindByPosition(Uri, String[]) Método
Definição
Cria um novo URI com base no modelo e uma matriz de valores de parâmetro.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
Parâmetros
- values
- String[]
Os valores de parâmetro.The parameter values.
Retornos
Uma nova instância de Uri.A new Uri instance.
Exemplos
O exemplo a seguir mostra como chamar o 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")
Comentários
Os valores de parâmetro são associados pela posição da esquerda para a direita.The parameter values are bound by position left to right. O primeiro valor de parâmetro substitui a primeira variável encontrada no modelo, o segundo valor de parâmetro substitui a segunda variável e assim por diante.The first parameter value replaces the first variable found in the template, the second parameter value replaces the second variable, and so on. As variáveis passadas para esse método são de escape.Variables passed to this method are escaped.
Observação
O número de parâmetros passados no parâmetro Values deve corresponder ao número de variáveis no modelo.The number of parameters passed in the values parameter must match the number of variables in the template. Caso contrário, um FormatException será lançado.If not, a FormatException is thrown.
Observação
É possível passar texto dentro da matriz de valores de parâmetro que impede que o URI gerado corresponda ao modelo usado para gerá-lo.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. Exemplos de tal texto incluem: '/', '. ', '.. ', ' * ', ' {' e '} '.Examples of such text includes: '/', '.','..', '*', '{', and '}'. O código a seguir demonstra isso.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