forked from philiplaureano/LinFu.DynamicProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyCache.cs
42 lines (35 loc) · 1.08 KB
/
ProxyCache.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
using System;
using System.Collections.Generic;
namespace LinFu.DynamicProxy
{
public class ProxyCache : IProxyCache
{
private static readonly Dictionary<ProxyCacheEntry, Type> _cache = new Dictionary<ProxyCacheEntry, Type>();
private static readonly object _lock = new object();
#region IProxyCache Members
public bool Contains(Type baseType, params Type[] baseInterfaces)
{
if (baseType == null)
return false;
ProxyCacheEntry entry = new ProxyCacheEntry(baseType, baseInterfaces);
return _cache.ContainsKey(entry);
}
public Type GetProxyType(Type baseType, params Type[] baseInterfaces)
{
lock (_lock)
{
ProxyCacheEntry entry = new ProxyCacheEntry(baseType, baseInterfaces);
return _cache[entry];
}
}
public void StoreProxyType(Type result, Type baseType, params Type[] baseInterfaces)
{
lock (_lock)
{
ProxyCacheEntry entry = new ProxyCacheEntry(baseType, baseInterfaces);
_cache[entry] = result;
}
}
#endregion
}
}