System.UriTemplateTable.Match 方法
方法描述
尝试将候选 Uri 与 UriTemplateTable 匹配。
语法定义(C# System.UriTemplateTable.Match 方法 的用法)
public CollectionMatch( Uri uri )
参数/返回值
| 参数值/返回值 | 参数类型/返回类型 | 参数描述/返回描述 |
|---|---|---|
| uri | System-Uri | 候选 URI。 |
| 返回值 | System.Collections.ObjectModel.Collection |
UriTemplateMatch 实例的集合。 |
提示和注释
此方法可能会返回多个匹配项。
System.UriTemplateTable.Match 方法例子
下面的示例演示如何调用 Match(Uri) 方法。
Uri prefix = new Uri("http://localhost/");
//Create a series of templates
UriTemplate weatherByCity = new UriTemplate("weather/ state}/ city}");
UriTemplate weatherByCountry = new UriTemplate("weather/ country}/ village}");
UriTemplate weatherByState = new UriTemplate("weather/ state}");
UriTemplate traffic = new UriTemplate("traffic/*");
UriTemplate wildcard = new UriTemplate("*");
//Create a template table
UriTemplateTable table = new UriTemplateTable(prefix);
//Add each template to the table with some associated data
table.KeyValuePairs.Add(new KeyValuePair(weatherByCity, "weatherByCity"));
table.KeyValuePairs.Add(new KeyValuePair(weatherByCountry, "weatherByCountry"));
table.KeyValuePairs.Add(new KeyValuePair(weatherByState, "weatherByState"));
table.KeyValuePairs.Add(new KeyValuePair(traffic, "traffic"));
table.MakeReadOnly(true);
//Call Match to retrieve some match results:
ICollection results = null;
Uri weatherInSeattle = new Uri("http://localhost/weather/Washington/Seattle");
results = table.Match(weatherInSeattle);
if( results != null)
{
Console.WriteLine("Matching templates:");
foreach (UriTemplateMatch match in results)
{
Console.WriteLine(" 0}", match.Template);
}
}
版本信息
.NET Framework 受以下版本支持:4、3.5 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1
适用平台
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。