[amd64/tramp] hide interpreter specific trampoline behind ifdef
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / Microsoft.Tools.Common / Microsoft / Activities / Presentation / Xaml / ResolverCache.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace Microsoft.Activities.Presentation.Xaml
8 {
9     using System;
10     using System.Collections.Generic;
11
12     internal class ResolverCache
13     {
14         private Dictionary<Type, WeakReference> cache;
15
16         public ResolverCache()
17         {
18             this.cache = new Dictionary<Type, WeakReference>();
19         }
20
21         public void Update(Type type, ResolverResult result)
22         {
23             SharedFx.Assert(type != null, "type should not be null");
24             SharedFx.Assert(result != null, "result should not be null");
25
26             if (this.cache.ContainsKey(type))
27             {
28                 this.cache[type] = new WeakReference(result);
29             }
30             else
31             {
32                 this.cache.Add(type, new WeakReference(result));
33             }
34         }
35
36         public ResolverResult Lookup(Type type)
37         {
38             SharedFx.Assert(type != null, "type should not be null");
39
40             WeakReference value;
41             if (this.cache.TryGetValue(type, out value))
42             {
43                 return value.Target as ResolverResult;
44             }
45
46             return null;
47         }
48     }
49 }