UriTemplateMatch.RelativePathSegments 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取相对路径段的集合。
public:
property System::Collections::ObjectModel::Collection<System::String ^> ^ RelativePathSegments { System::Collections::ObjectModel::Collection<System::String ^> ^ get(); };
public System.Collections.ObjectModel.Collection<string> RelativePathSegments { get; }
member this.RelativePathSegments : System.Collections.ObjectModel.Collection<string>
Public ReadOnly Property RelativePathSegments As Collection(Of String)
属性值
相对路径段的集合。
示例
下面的代码演示如何访问 RelativePathSegments 属性。
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)
{
Console.WriteLine("RelativePathSegments:");
foreach (string segment in results.RelativePathSegments)
{
Console.WriteLine(" {0}", segment);
}
}
// Code output:
// RelativePathSegments:
// weather
// wa
// seattle
Dim template As New UriTemplate("weather/ state}/ city}?forecast=today")
Dim baseAddress As New Uri("http://localhost")
Dim fullUri As 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
Dim results As UriTemplateMatch = template.Match(baseAddress, fullUri)
If (results IsNot Nothing) Then
Console.WriteLine("RelativePathSegments:")
For Each segment As String In results.RelativePathSegments
Console.WriteLine(" 0}", segment)
Next
End If
'Code output:
'RelativePathSegments:
' weather
' wa
' seattle
注解
此属性包含与模板匹配的候选 URI 中的路径段以及与模板通配符匹配的路径段的集合。 WildcardPathSegments 属性也包含与模板通配符匹配的路径段。