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})입니다. 짝이 없는 값은 사용할 수 없습니다. 다음 예제에서는 유효한 템플릿 문자열을 보여 줍니다.

  • "weather/WA/Seattle"

  • "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[])를 만들 수도 있습니다.

생성자

UriTemplate(String)

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

UriTemplate(String, Boolean)

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

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

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

UriTemplate(String, IDictionary<String,String>)

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

속성

Defaults

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

IgnoreTrailingSlash

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

PathSegmentVariableNames

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

QueryValueVariableNames

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

메서드

BindByName(Uri, IDictionary<String,String>)

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

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

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

BindByName(Uri, NameValueCollection)

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

BindByName(Uri, NameValueCollection, Boolean)

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

BindByPosition(Uri, String[])

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

Equals(Object)

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

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

기본 해시 함수로 작동합니다.

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

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

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

UriTemplate이 다른 템플릿과 구조적으로 같은지 여부를 나타냅니다.

Match(Uri, Uri)

UriUriTemplate과 일치시키려고 시도합니다.

MemberwiseClone()

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

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

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

적용 대상