forked from philiplaureano/LinFu.DynamicProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyCacheEntry.cs
57 lines (49 loc) · 1.45 KB
/
ProxyCacheEntry.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
namespace LinFu.DynamicProxy
{
public struct ProxyCacheEntry
{
private readonly int hashCode;
public Type BaseType;
public Type[] Interfaces;
public ProxyCacheEntry(Type baseType, Type[] interfaces)
{
if (baseType == null)
{
throw new ArgumentNullException("baseType");
}
BaseType = baseType;
Interfaces = interfaces;
if (interfaces == null || interfaces.Length == 0)
{
hashCode = baseType.GetHashCode();
return;
}
// duplicated type exclusion
Dictionary<Type, object> set = new Dictionary<Type, object>(interfaces.Length + 1);
set[baseType] = null;
foreach (Type type in interfaces)
{
if (type != null)
set[type] = null;
}
hashCode = 0;
foreach (Type type in set.Keys)
{
hashCode ^= type.GetHashCode();
}
}
public override bool Equals(object obj)
{
if (!(obj is ProxyCacheEntry))
return false;
ProxyCacheEntry other = (ProxyCacheEntry)obj;
return hashCode == other.GetHashCode();
}
public override int GetHashCode()
{
return hashCode;
}
}
}