UriTemplateEquivalenceComparer 클래스

정의

UriTemplate 인스턴스의 참조 동등성이 아닌 구조적 동등성을 비교하는 데 사용하는 클래스입니다.A class used to compare UriTemplate instances for structural (instead of reference) equivalence.

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
구현

예제

다음 예제에서는 참조 일치와 구조적 일치의 차이를 보여 줍니다.The following example shows the difference between reference equality and structural equality. 또한 사전에서 UriTemplateEquivalenceComparer를 비교자로 사용하는 방법도 보여 줍니다.It also shows how to use the UriTemplateEquivalenceComparer as a comparer in a dictionary.

// 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 인스턴스는 기본적으로 참조 일치를 사용하여 비교합니다.UriTemplate instances are compared using reference equality by default. UriTemplateEquivalenceComparer 클래스는 기본 참조 일치 검사 대신 IsEquivalentTo(UriTemplate)를 사용하여 동등성을 평가합니다.The UriTemplateEquivalenceComparer class evaluates equivalence using IsEquivalentTo(UriTemplate) instead of the default reference equality check. 이 클래스는 엄격한 참조 일치 대신 일치 작업 대상 URI를 기반으로 하여 두 개의 UriTemplate 인스턴스를 비교할 때 유용합니다.This class is useful when you wish to compare two UriTemplate instances based on the URIs they match instead of strict reference equality.

생성자

UriTemplateEquivalenceComparer()

UriTemplateEquivalenceComparer 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the UriTemplateEquivalenceComparer class.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.Determines whether the specified object is equal to the current object.

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

UriTemplate 인스턴스가 같은지 비교합니다.Compares two UriTemplate instances for equivalence.

GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

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

지정한 UriTemplate 인스턴스에 대한 해시 코드를 가져옵니다.Gets a hash code for the specified UriTemplate instance.

GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

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

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

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

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(다음에서 상속됨 Object)

적용 대상