System.UriTemplateMatch 类
方法描述
一个类,表示对 UriTemplate 实例执行匹配操作的结果。
语法定义(C# System.UriTemplateMatch 类 的用法)
public class UriTemplateMatch
构造函数
| 构造函数名称 | 构造函数描述 | 
|---|---|
| UriTemplateMatch | 初始化 UriTemplateMatch 类的新实例。 | 
成员/方法
| 方法名称 | 方法描述 | 
|---|---|
| Equals(Object) | 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。) | 
| Finalize | 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。) | 
| GetHashCode | 用作特定类型的哈希函数。 (继承自 Object。) | 
| GetType | 获取当前实例的 Type。 (继承自 Object。) | 
| MemberwiseClone | 创建当前 Object 的浅表副本。 (继承自 Object。) | 
| ToString | 返回表示当前对象的字符串。 (继承自 Object。) | 
提示和注释
UriTemplateMatch 类表示调用 Match(Uri, Uri) 方法的结果。此类不是线程安全的。
System.UriTemplateMatch 类例子
下面的代码演示如何使用 UriTemplateMatch 类。
UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast=today");
Uri baseAddress = new Uri("http://localhost");
Uri fullUri = new Uri("http://localhost/weather/WA/Seattle?forecast=today");
Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());
// Match a URI to a template
UriTemplateMatch results = template.Match(baseAddress, fullUri);
if (results != null)
{
    // BaseUri
    Console.WriteLine("BaseUri: {0}", results.BaseUri);
    Console.WriteLine("BoundVariables:");
    foreach (string variableName in results.BoundVariables.Keys)
    {
        Console.WriteLine("    {0}: {1}", variableName, results.BoundVariables[variableName]);
    }
    Console.WriteLine("QueryParameters:");
    foreach (string queryName in results.QueryParameters.Keys)
    {
        Console.WriteLine("    {0} : {1}", queryName, results.QueryParameters[queryName]);
    }
    Console.WriteLine();
    Console.WriteLine("RelativePathSegments:");
    foreach (string segment in results.RelativePathSegments)
    {
        Console.WriteLine("     {0}", segment);
    }
    Console.WriteLine();
    Console.WriteLine("RequestUri:");
    Console.WriteLine(results.RequestUri);
    Console.WriteLine("Template:");
    Console.WriteLine(results.Template);
    Console.WriteLine("WildcardPathSegments:");
    foreach (string segment in results.WildcardPathSegments)
    {
        Console.WriteLine("     {0}", segment);
    }
    Console.WriteLine();
}
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
版本信息
.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 系统要求。