UriTemplateEquivalenceComparer 클래스

정의

참조 대신 구조적 동등성을 위해 인스턴스를 비교 UriTemplate 하는 데 사용되는 클래스입니다.

public ref class UriTemplateEquivalenceComparer : System::Collections::Generic::IEqualityComparer<UriTemplate ^>
public class UriTemplateEquivalenceComparer : System.Collections.Generic.IEqualityComparer<UriTemplate>
type UriTemplateEquivalenceComparer = class
    interface IEqualityComparer<UriTemplate>
Public Class UriTemplateEquivalenceComparer
Implements IEqualityComparer(Of UriTemplate)
상속
UriTemplateEquivalenceComparer
구현

예제

다음 예제에서는 참조 같음과 구조적 같음의 차이를 보여 있습니다. 또한 사전에서 비교자로 사용하는 UriTemplateEquivalenceComparer 방법을 보여줍니다.

// Define two structurally equivalent templates
UriTemplate temp1 = new UriTemplate("weather/{state}/{city}");
UriTemplate temp2 = new UriTemplate("weather/{country}/{village}");

// Notice they are not reference equal, in other words
// they are do not refer to the same object
if (temp1 == temp2)
    Console.WriteLine("{0} and {1} are reference equal", temp1, temp2);
else
    Console.WriteLine("{0} and {1} are NOT reference equal", temp1, temp2);

// Notice they are structrually equal
if (temp1.IsEquivalentTo(temp2))
    Console.WriteLine("{0} and {1} are structurally equal", temp1, temp2);
else
    Console.WriteLine("{0} and {1} are NOT structurally equal", temp1, temp2);

// Create a dictionary and use UriTemplateEquivalenceComparer as the comparer
Dictionary<UriTemplate, object> templates = new Dictionary<UriTemplate, object>(new UriTemplateEquivalenceComparer());

// Add template 1 into the dictionary
templates.Add(temp1, "template1");

// The UriTemplateEquivalenceComparer will be used here to compare the template in the table with template2
// they are structurally equivalent, so ContainsKey will return true.
if (templates.ContainsKey(temp2))
    Console.WriteLine("Both templates hash to the same value");
else
    Console.WriteLine("Both templates do NOT hash to the same value");
'Define two structurally equivalent templates
Dim temp1 As UriTemplate = New UriTemplate("weather/{state}/{city}")
Dim temp2 As UriTemplate = New UriTemplate("weather/{country}/{village}")

'Notice they are not reference equal, in other words
'they are do not refer to the same object
If temp1.Equals(temp2) Then
    Console.WriteLine("{0} and {1} are reference equal", temp1, temp2)
Else
    Console.WriteLine("{0} and {1} are NOT reference equal", temp1, temp2)
End If

'Notice they are structrually equal
If (temp1.IsEquivalentTo(temp2)) Then
    Console.WriteLine("{0} and {1} are structurally equal", temp1, temp2)
Else
    Console.WriteLine("{0} and {1} are NOT structurally equal", temp1, temp2)
End If

'Create a dictionary and use UriTemplateEquivalenceComparer as the comparer
Dim templates As Dictionary(Of UriTemplate, Object) = New Dictionary(Of UriTemplate, Object)(New UriTemplateEquivalenceComparer())

'Add template 1 into the dictionary
templates.Add(temp1, "template1")

'The UriTemplateEquivalenceComparer will be used here to compare the template in the table with template2
'they are structurally equivalent, so ContainsKey will return true.
If (templates.ContainsKey(temp2)) Then
    Console.WriteLine("Both templates hash to the same value")
Else
    Console.WriteLine("Both templates do NOT hash to the same value")
End If

설명

UriTemplate 인스턴스는 기본적으로 참조 같음을 사용하여 비교됩니다. 클래스는 UriTemplateEquivalenceComparer 기본 참조 같음 검사 대신 동등 IsEquivalentTo(UriTemplate) 성을 평가합니다. 이 클래스는 엄격한 참조 같음 대신 일치하는 URI를 기반으로 두 UriTemplate 인스턴스를 비교하려는 경우에 유용합니다.

생성자

Name Description
UriTemplateEquivalenceComparer()

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

메서드

Name Description
Equals(Object)

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

(다음에서 상속됨 Object)
Equals(UriTemplate, UriTemplate)

UriTemplate 인스턴스를 동등성을 비교합니다.

GetHashCode()

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

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

지정된 UriTemplate 인스턴스에 대한 해시 코드를 가져옵니다.

GetType()

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

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

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

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

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상