UriTemplate.BindByName 方法
定义
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters.
重载
| BindByName(Uri, IDictionary<String,String>) |
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters. |
| BindByName(Uri, NameValueCollection) |
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters. |
| BindByName(Uri, IDictionary<String,String>, Boolean) |
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters. |
| BindByName(Uri, NameValueCollection, Boolean) |
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters. |
BindByName(Uri, IDictionary<String,String>)
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters.
public:
Uri ^ BindByName(Uri ^ baseAddress, System::Collections::Generic::IDictionary<System::String ^, System::String ^> ^ parameters);
public Uri BindByName (Uri baseAddress, System.Collections.Generic.IDictionary<string,string> parameters);
member this.BindByName : Uri * System.Collections.Generic.IDictionary<string, string> -> Uri
Public Function BindByName (baseAddress As Uri, parameters As IDictionary(Of String, String)) As Uri
参数
- baseAddress
- Uri
基址。The base address.
- parameters
- IDictionary<String,String>
一个字典,其中包含参数名称/值对的集合。A dictionary that contains a collection of parameter name/value pairs.
返回
一个 URI。A URI.
注解
IDictionary <string,string> 参数包含参数名称和值对的集合。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.
备注
传递给此方法的名称/值集合必须包含每个模板变量的键值。The name/value collection passed to this method must contain a key for every template variable. 与模板变量不匹配的额外名称/值对会追加到最终 URI 的查询字符串之后。Extra name/value pairs that do not match template variables are appended to the query string of the final URI.
重要
您可以在名称/值对中传入文本,以阻止生成的 URI 与用于生成它的模板匹配。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 '}'.
适用于
BindByName(Uri, NameValueCollection)
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters.
public:
Uri ^ BindByName(Uri ^ baseAddress, System::Collections::Specialized::NameValueCollection ^ parameters);
public Uri BindByName (Uri baseAddress, System.Collections.Specialized.NameValueCollection parameters);
member this.BindByName : Uri * System.Collections.Specialized.NameValueCollection -> Uri
Public Function BindByName (baseAddress As Uri, parameters As NameValueCollection) As Uri
参数
- baseAddress
- Uri
基址。The base address.
- parameters
- NameValueCollection
参数值。The parameter values.
返回
新实例。A new instance.
示例
下面的示例演示如何调用 BindByName(Uri, NameValueCollection) 方法。The following example shows how to call the BindByName(Uri, NameValueCollection) method.
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);
Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")
Dim parameters As NameValueCollection = New NameValueCollection()
parameters.Add("state", "Washington")
parameters.Add("city", "Redmond")
parameters.Add("day", "Today")
Dim namedUri As Uri = template.BindByName(prefix, parameters)
注解
NameValueCollection 参数包含参数名称/值对的集合。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.
备注
传递给 BindByName(Uri, NameValueCollection) 的名称/值集合必须包含每个模板变量的键值。The name/value collection passed to BindByName(Uri, NameValueCollection) must contain a key for every template variable. 与模板变量不匹配的额外名称/值对会追加到最终 URI 的查询字符串之后。Extra name/value pairs that do not match template variables are appended to the query string of the final URI.
备注
您可以在名称/值对中传入文本,以阻止生成的 URI 与用于生成它的模板匹配。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 '}'.
适用于
BindByName(Uri, IDictionary<String,String>, Boolean)
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters.
public:
Uri ^ BindByName(Uri ^ baseAddress, System::Collections::Generic::IDictionary<System::String ^, System::String ^> ^ parameters, bool omitDefaults);
public Uri BindByName (Uri baseAddress, System.Collections.Generic.IDictionary<string,string> parameters, bool omitDefaults);
member this.BindByName : Uri * System.Collections.Generic.IDictionary<string, string> * bool -> Uri
Public Function BindByName (baseAddress As Uri, parameters As IDictionary(Of String, String), omitDefaults As Boolean) As Uri
参数
- baseAddress
- Uri
一个包含基址的 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;否则为 false。true is the default values are ignored; otherwise false.
返回
一个 URI。A URI.
适用于
BindByName(Uri, NameValueCollection, Boolean)
利用模板和参数集合创建一个新的 URI。Creates a new URI from the template and the collection of parameters.
public:
Uri ^ BindByName(Uri ^ baseAddress, System::Collections::Specialized::NameValueCollection ^ parameters, bool omitDefaults);
public Uri BindByName (Uri baseAddress, System.Collections.Specialized.NameValueCollection parameters, bool omitDefaults);
member this.BindByName : Uri * System.Collections.Specialized.NameValueCollection * bool -> Uri
Public Function BindByName (baseAddress As Uri, parameters As NameValueCollection, omitDefaults As Boolean) As Uri
参数
- baseAddress
- Uri
基址。The base address.
- parameters
- NameValueCollection
参数名称/值对的集合。A collection of parameter name/value pairs.
- omitDefaults
- Boolean
如果忽略默认值,则为 true;否则为 false。true if the default values are ignored; otherwise false.
返回
一个 URI。A URI.