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 屬性中。