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
37 lines (30 loc) · 1022 Bytes
/
MemberComparer.cs
File metadata and controls
37 lines (30 loc) · 1022 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
37
// 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
{
private static readonly MemberComparer<T> instance = new MemberComparer<T>();
public static MemberComparer<T> Instance { get { return instance; } }
public override bool Equals(T x, T y)
{
// ReSharper disable PossibleNullReferenceException
try
{
return (x.Module == y.Module) && (x.MetadataToken == y.MetadataToken);
}
catch (Exception)
{
return x == y;
}
// ReSharper restore PossibleNullReferenceException
}
public override int GetHashCode(T obj)
{
return (obj == null) ? 0 : obj.GetHashCode();
}
}
}