UriTemplate 클래스

정의

URI(Uniform Resource Identifier) 템플릿을 나타내는 클래스입니다.

public ref class UriTemplate
public class UriTemplate
type UriTemplate = class
Public Class UriTemplate
상속
UriTemplate

예제

다음 코드에서는 인스턴스를 만들고 UriTemplate 후보 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 집합을 정의할 수 있습니다. 템플릿은 경로와 쿼리의 두 부분으로 구성됩니다. 경로는 슬래시(/)로 구분된 일련의 세그먼트로 구성됩니다. 각 세그먼트에는 리터럴 값, 변수 값(정확히 한 세그먼트의 내용과 일치하도록 제한된 중괄호 [{ }] 내에 작성됨) 또는 경로의 끝에 나타나야 하는 와일드카드(별표 [*]로 작성됨)가 있을 수 있습니다. 쿼리 식은 완전히 생략할 수 있습니다. 있는 경우 순서가 지정되지 않은 일련의 이름/값 쌍을 지정합니다. 쿼리 식의 요소는 리터럴 쌍(?x=2) 또는 변수 쌍(?x={val})일 수 있습니다. 2진수 값은 허용되지 않습니다. 다음 예제에서는 유효한 템플릿 문자열을 보여 줍니다.

  • "날씨/WA/시애틀"

  • "weather/{state}/{city}"

  • "weather/*"

  • "weather/{state}/{city}?forecast=today

  • "weather/{state}/{city}?forecast={day}

위의 URI 템플릿은 날씨 보고서를 구성하는 데 사용될 수 있습니다. 중괄호로 묶인 세그먼트는 변수이고, 다른 모든 항목은 리터럴입니다. 변수를 UriTemplate 실제 값으로 Uri 바꿔 인스턴스를 변환할 수 있습니다. 예를 들어 템플릿 "weather/{state}/{city}"를 사용하고 변수 "{state}" 및 "{city}"에 대한 값을 입력하면 "weather/WA/Seattle"이 제공됩니다. 후보 URI가 지정된 경우 호출 Match(Uri, Uri)하여 지정된 URI 템플릿과 일치하는지 테스트할 수 있습니다. 인스턴스를 사용하여 UriTemplate 호출 Uri 하거나 하여 변수 값 집합에서 만들 BindByName(Uri, NameValueCollection) 수도 BindByPosition(Uri, String[])있습니다.

생성자

Name Description
UriTemplate(String, Boolean, IDictionary<String,String>)

UriTemplate 클래스의 새 인스턴스를 초기화합니다.

UriTemplate(String, Boolean)

UriTemplate 클래스의 새 인스턴스를 초기화합니다.

UriTemplate(String, IDictionary<String,String>)

UriTemplate 클래스의 새 인스턴스를 초기화합니다.

UriTemplate(String)

지정된 템플릿 문자열을 사용하여 클래스의 UriTemplate 새 인스턴스를 초기화합니다.

속성

Name Description
Defaults

기본 매개 변수 값에 대한 이름/값 쌍의 컬렉션을 가져옵니다.

IgnoreTrailingSlash

후보 URI를 일치할 때 템플릿의 후행 슬래시 "/"를 무시할지 여부를 지정합니다.

PathSegmentVariableNames

템플릿의 경로 세그먼트 내에서 사용되는 변수 이름의 컬렉션을 가져옵니다.

QueryValueVariableNames

템플릿의 쿼리 문자열 내에서 사용되는 변수 이름의 컬렉션을 가져옵니다.

메서드

Name Description
BindByName(Uri, IDictionary<String,String>, Boolean)

템플릿 및 매개 변수 컬렉션에서 새 URI를 만듭니다.

BindByName(Uri, IDictionary<String,String>)

템플릿 및 매개 변수 컬렉션에서 새 URI를 만듭니다.

BindByName(Uri, NameValueCollection, Boolean)

템플릿 및 매개 변수 컬렉션에서 새 URI를 만듭니다.

BindByName(Uri, NameValueCollection)

템플릿 및 매개 변수 컬렉션에서 새 URI를 만듭니다.

BindByPosition(Uri, String[])

템플릿에서 새 URI와 매개 변수 값 배열을 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
IsEquivalentTo(UriTemplate)

구조 UriTemplate 적으로 다른 항목과 동일한지 여부를 나타냅니다.

Match(Uri, Uri)

에 대한 일치 Uri 를 시도합니다 UriTemplate.

MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

인스턴스의 문자열 표현을 반환합니다 UriTemplate .

적용 대상