aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Translation/DelegateCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure/Translation/DelegateCache.cs')
-rw-r--r--ARMeilleure/Translation/DelegateCache.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/ARMeilleure/Translation/DelegateCache.cs b/ARMeilleure/Translation/DelegateCache.cs
new file mode 100644
index 00000000..7328c61a
--- /dev/null
+++ b/ARMeilleure/Translation/DelegateCache.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Concurrent;
+using System.Reflection;
+
+namespace ARMeilleure.Translation
+{
+ static class DelegateCache
+ {
+ private static ConcurrentDictionary<string, Delegate> _delegates;
+
+ static DelegateCache()
+ {
+ _delegates = new ConcurrentDictionary<string, Delegate>();
+ }
+
+ public static Delegate GetOrAdd(Delegate dlg)
+ {
+ return _delegates.GetOrAdd(GetKey(dlg.Method), (key) => dlg);
+ }
+
+ private static string GetKey(MethodInfo info)
+ {
+ return $"{info.DeclaringType.FullName}.{info.Name}";
+ }
+ }
+} \ No newline at end of file