UriTemplate 클래스
정의
URI(Uniform Resource Identifier) 템플릿을 나타내는 클래스입니다.A class that represents a Uniform Resource Identifier (URI) template.
public ref class UriTemplate
public class UriTemplate
type UriTemplate = class
Public Class UriTemplate
- 상속
-
UriTemplate
예제
다음 코드에서는 UriTemplate 인스턴스를 만들고 바인딩하여 후보 URI와 일치시키는 방법을 보여 줍니다.The following code demonstrates how to create a UriTemplate instance, and bind and match it to a candidate URI.
UriTemplate template = new UriTemplate("weather/{state}/{city}?forecast={day}");
Uri prefix = new Uri("http://localhost");
Console.WriteLine("PathSegmentVariableNames:");
foreach (string name in template.PathSegmentVariableNames)
{
Console.WriteLine(" {0}", name);
}
Console.WriteLine();
Console.WriteLine("QueryValueVariableNames:");
foreach (string name in template.QueryValueVariableNames)
{
Console.WriteLine(" {0}", name);
}
Console.WriteLine();
Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond", "Today");
NameValueCollection parameters = new NameValueCollection();
parameters.Add("state", "Washington");
parameters.Add("city", "Redmond");
parameters.Add("day", "Today");
Uri namedUri = template.BindByName(prefix, parameters);
Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond?forecast=today");
UriTemplateMatch results = template.Match(prefix, fullUri);
Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString());
if (results != null)
{
foreach (string variableName in results.BoundVariables.Keys)
{
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables[variableName]);
}
}
Dim template As UriTemplate = New UriTemplate("weather/{state}/{city}?forecast={day}")
Dim prefix As Uri = New Uri("http://localhost")
Console.WriteLine("PathSegmentVariableNames:")
For Each name As String In template.PathSegmentVariableNames
Console.WriteLine(" {0}", name)
Next
Console.WriteLine()
Console.WriteLine("QueryValueVariableNames:")
For Each name As String In template.QueryValueVariableNames
Console.WriteLine(" {0}", name)
Next
Console.WriteLine()
Dim positionalUri As Uri = template.BindByPosition(prefix, "Washington", "Redmond", "Today")
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)
Dim fullUri As Uri = New Uri("http://localhost/weather/Washington/Redmond?forecast=today")
Dim results As UriTemplateMatch = template.Match(prefix, fullUri)
Console.WriteLine("Matching {0} to {1}", template.ToString(), fullUri.ToString())
If results IsNot Nothing Then
For Each variableName As String In results.BoundVariables.Keys
Console.WriteLine(" {0}: {1}", variableName, results.BoundVariables(variableName))
Next
End If
설명
URI 템플릿을 사용하면 구조적으로 비슷한 URI 집합을 정의할 수 있습니다.A URI template allows you to define a set of structurally similar URIs. 템플릿은 경로와 쿼리의 두 부분으로 구성됩니다.Templates are composed of two parts, a path and a query. 경로는 슬래시(/)로 구분된 세그먼트로 구성됩니다.A path consists of a series of segments delimited by a slash (/). 각 세그먼트는 리터럴 값, 변수 값(중괄호[{ }]로 표시, 정확히 한 세그먼트의 내용과 일치하도록 제약) 또는 와일드카드(별표[*]로 표시, "나머지 경로"와 일치)를 가질 수 있으며, 이러한 값은 경로의 끝에 표시되어야 합니다.Each segment can have a literal value, a variable value (written within curly braces [{ }], constrained to match the contents of exactly one segment), or a wildcard (written as an asterisk [*], which matches "the rest of the path"), which must appear at the end of the path. 쿼리 식은 완전히 생략할 수 있습니다.The query expression can be omitted entirely. 쿼리 식(있는 경우)은 순서가 지정되지 않은 이름/값 쌍을 지정합니다.If present, it specifies an unordered series of name/value pairs. 쿼리 식의 요소는 리터럴 쌍(?x=2) 또는 변수 쌍(?x={val})입니다.Elements of the query expression can be either literal pairs (?x=2) or variable pairs (?x={val}). 짝이 없는 값은 사용할 수 없습니다.Unpaired values are not permitted. 다음 예제에서는 유효한 템플릿 문자열을 보여 줍니다.The following examples show valid template strings:
"weather/WA/Seattle""weather/WA/Seattle"
"weather/{state}/{city}""weather/{state}/{city}"
"weather/*""weather/*"
"weather/{state}/{city}?forecast=today"weather/{state}/{city}?forecast=today
"weather/{state}/{city}?forecast={day}"weather/{state}/{city}?forecast={day}
앞에 나온 URI 템플릿은 날씨 보고서를 구성할 때 사용할 수 있습니다.The preceding URI templates might be used for organizing weather reports. 중괄호로 묶인 세그먼트는 변수이며, 나머지는 모두 리터럴입니다.Segments enclosed in curly braces are variables, everything else is a literal. 변수를 실제 값으로 대체하여 UriTemplate 인스턴스를 Uri로 변환할 수 있습니다.You can convert a UriTemplate instance into a Uri by replacing variables with actual values. 예를 들어, "weather/{state}/{city}" 템플릿에서 "{state}" 및 "{city}" 변수의 값을 입력하면 "weather/WA/Seattle"이 됩니다.For example, taking the template "weather/{state}/{city}" and putting in values for the variables "{state}" and "{city}" gives you "weather/WA/Seattle". 후보 URI가 있으면 Match(Uri, Uri)를 호출하여 특정 URI 템플릿과 일치하는지 테스트할 수 있습니다.Given a candidate URI, you can test whether it matches a given URI template by calling Match(Uri, Uri). UriTemplate 인스턴스를 사용하면 Uri이나 BindByName(Uri, NameValueCollection)을 호출하여 변수 값의 집합으로부터 BindByPosition(Uri, String[])를 만들 수도 있습니다.You can also use UriTemplate instances to create a Uri from a set of variable values by calling BindByName(Uri, NameValueCollection) or BindByPosition(Uri, String[]).
생성자
UriTemplate(String) |
지정된 템플릿 문자열을 사용하여 UriTemplate 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the UriTemplate class with the specified template string. |
UriTemplate(String, Boolean) |
UriTemplate 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the UriTemplate class. |
UriTemplate(String, Boolean, IDictionary<String,String>) |
UriTemplate 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the UriTemplate class. |
UriTemplate(String, IDictionary<String,String>) |
UriTemplate 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the UriTemplate class. |
속성
Defaults |
매개 변수 기본값에 대한 이름/값 쌍 컬렉션을 가져옵니다.Gets a collection of name/value pairs for any default parameter values. |
IgnoreTrailingSlash |
후보 URI와 일치시킬 때 템플릿의 후행 슬래시("/")를 무시할지 여부를 지정합니다.Specifies whether trailing slashes "/" in the template should be ignored when matching candidate URIs. |
PathSegmentVariableNames |
템플릿의 경로 세그먼트에 사용되는 변수 이름 컬렉션을 가져옵니다.Gets a collection of variable names used within path segments in the template. |
QueryValueVariableNames |
템플릿의 쿼리 문자열에 사용되는 변수 이름 컬렉션을 가져옵니다.Gets a collection of variable names used within the query string in the template. |
메서드
BindByName(Uri, IDictionary<String,String>) |
템플릿에서 새 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) |
템플릿에서 새 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. |
BindByPosition(Uri, String[]) |
템플릿에서 새 URI를 만들고 매개 변수 값 배열을 만듭니다.Creates a new URI from the template and an array of parameter values. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다.Determines whether the specified object is equal to the current object. (다음에서 상속됨 Object) |
GetHashCode() |
기본 해시 함수로 작동합니다.Serves as the default hash function. (다음에서 상속됨 Object) |
GetType() |
현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance. (다음에서 상속됨 Object) |
IsEquivalentTo(UriTemplate) |
UriTemplate이 다른 템플릿과 구조적으로 같은지 여부를 나타냅니다.Indicates whether a UriTemplate is structurally equivalent to another. |
Match(Uri, Uri) |
Uri를 UriTemplate과 일치시키려고 시도합니다.Attempts to match a Uri to a UriTemplate. |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
ToString() |
UriTemplate 인스턴스의 문자열 표현을 반환합니다.Returns a string representation of the UriTemplate instance. |