forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemberComparer.cs
More file actions
36 lines (31 loc) · 933 Bytes
/
MemberComparer.cs
File metadata and controls
36 lines (31 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Microsoft.ClearScript.Util
{
internal sealed class MemberComparer<T> : EqualityComparer<T> where T : MemberInfo
{
public static MemberComparer<T> Instance { get; } = new MemberComparer<T>();
private MemberComparer()
{
}
public override bool Equals(T x, T y)
{
try
{
return (x.Module == y.Module) && (x.MetadataToken == y.MetadataToken);
}
catch (Exception)
{
return x == y;
}
}
public override int GetHashCode(T obj)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
return (obj == null) ? 0 : obj.GetHashCode();
}
}
}