diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/YEngine/MMRDelegateCommon.cs (renamed from OpenSim/Region/ScriptEngine/XMREngine/MMRDelegateCommon.cs) | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/MMRDelegateCommon.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRDelegateCommon.cs index 48b665b..433062a 100644 --- a/OpenSim/Region/ScriptEngine/XMREngine/MMRDelegateCommon.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRDelegateCommon.cs | |||
@@ -30,65 +30,76 @@ using System.Collections.Generic; | |||
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Reflection.Emit; | 31 | using System.Reflection.Emit; |
32 | 32 | ||
33 | namespace OpenSim.Region.ScriptEngine.XMREngine { | 33 | namespace OpenSim.Region.ScriptEngine.Yengine |
34 | { | ||
34 | 35 | ||
35 | public class DelegateCommon { | 36 | public class DelegateCommon |
37 | { | ||
36 | private string sig; // rettype(arg1type,arg2type,...), eg, "void(list,string,integer)" | 38 | private string sig; // rettype(arg1type,arg2type,...), eg, "void(list,string,integer)" |
37 | private Type type; // resultant delegate type | 39 | private Type type; // resultant delegate type |
38 | 40 | ||
39 | private static Dictionary<string, DelegateCommon> delegateCommons = new Dictionary<string, DelegateCommon> (); | 41 | private static Dictionary<string, DelegateCommon> delegateCommons = new Dictionary<string, DelegateCommon>(); |
40 | private static Dictionary<Type, DelegateCommon> delegateCommonsBySysType = new Dictionary<Type, DelegateCommon> (); | 42 | private static Dictionary<Type, DelegateCommon> delegateCommonsBySysType = new Dictionary<Type, DelegateCommon>(); |
41 | private static ModuleBuilder delegateModuleBuilder = null; | 43 | private static ModuleBuilder delegateModuleBuilder = null; |
42 | public static Type[] constructorArgTypes = new Type[] { typeof (object), typeof (IntPtr) }; | 44 | public static Type[] constructorArgTypes = new Type[] { typeof(object), typeof(IntPtr) }; |
43 | 45 | ||
44 | private DelegateCommon () { } | 46 | private DelegateCommon() |
47 | { | ||
48 | } | ||
45 | 49 | ||
46 | public static Type GetType (System.Type ret, System.Type[] args, string sig) | 50 | public static Type GetType(System.Type ret, System.Type[] args, string sig) |
47 | { | 51 | { |
48 | DelegateCommon dc; | 52 | DelegateCommon dc; |
49 | lock (delegateCommons) { | 53 | lock(delegateCommons) |
50 | if (!delegateCommons.TryGetValue (sig, out dc)) { | 54 | { |
51 | dc = new DelegateCommon (); | 55 | if(!delegateCommons.TryGetValue(sig, out dc)) |
52 | dc.sig = sig; | 56 | { |
53 | dc.type = CreateDelegateType (sig, ret, args); | 57 | dc = new DelegateCommon(); |
54 | delegateCommons.Add (sig, dc); | 58 | dc.sig = sig; |
55 | delegateCommonsBySysType.Add (dc.type, dc); | 59 | dc.type = CreateDelegateType(sig, ret, args); |
60 | delegateCommons.Add(sig, dc); | ||
61 | delegateCommonsBySysType.Add(dc.type, dc); | ||
56 | } | 62 | } |
57 | } | 63 | } |
58 | return dc.type; | 64 | return dc.type; |
59 | } | 65 | } |
60 | 66 | ||
61 | public static Type TryGetType (string sig) | 67 | public static Type TryGetType(string sig) |
62 | { | 68 | { |
63 | DelegateCommon dc; | 69 | DelegateCommon dc; |
64 | lock (delegateCommons) { | 70 | lock(delegateCommons) |
65 | if (!delegateCommons.TryGetValue (sig, out dc)) dc = null; | 71 | { |
72 | if(!delegateCommons.TryGetValue(sig, out dc)) | ||
73 | dc = null; | ||
66 | } | 74 | } |
67 | return (dc == null) ? null : dc.type; | 75 | return (dc == null) ? null : dc.type; |
68 | } | 76 | } |
69 | 77 | ||
70 | public static string TryGetName (Type t) | 78 | public static string TryGetName(Type t) |
71 | { | 79 | { |
72 | DelegateCommon dc; | 80 | DelegateCommon dc; |
73 | lock (delegateCommons) { | 81 | lock(delegateCommons) |
74 | if (!delegateCommonsBySysType.TryGetValue (t, out dc)) dc = null; | 82 | { |
83 | if(!delegateCommonsBySysType.TryGetValue(t, out dc)) | ||
84 | dc = null; | ||
75 | } | 85 | } |
76 | return (dc == null) ? null : dc.sig; | 86 | return (dc == null) ? null : dc.sig; |
77 | } | 87 | } |
78 | 88 | ||
79 | // http://blog.bittercoder.com/PermaLink,guid,a770377a-b1ad-4590-9145-36381757a52b.aspx | 89 | // http://blog.bittercoder.com/PermaLink,guid,a770377a-b1ad-4590-9145-36381757a52b.aspx |
80 | private static Type CreateDelegateType (string name, Type retType, Type[] argTypes) | 90 | private static Type CreateDelegateType(string name, Type retType, Type[] argTypes) |
81 | { | 91 | { |
82 | if (delegateModuleBuilder == null) { | 92 | if(delegateModuleBuilder == null) |
93 | { | ||
83 | AssemblyName assembly = new AssemblyName(); | 94 | AssemblyName assembly = new AssemblyName(); |
84 | assembly.Name = "CustomDelegateAssembly"; | 95 | assembly.Name = "CustomDelegateAssembly"; |
85 | AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assembly, AssemblyBuilderAccess.Run); | 96 | AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assembly, AssemblyBuilderAccess.Run); |
86 | delegateModuleBuilder = assemblyBuilder.DefineDynamicModule("CustomDelegateModule"); | 97 | delegateModuleBuilder = assemblyBuilder.DefineDynamicModule("CustomDelegateModule"); |
87 | } | 98 | } |
88 | 99 | ||
89 | TypeBuilder typeBuilder = delegateModuleBuilder.DefineType(name, | 100 | TypeBuilder typeBuilder = delegateModuleBuilder.DefineType(name, |
90 | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class | | 101 | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Class | |
91 | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, typeof (MulticastDelegate)); | 102 | TypeAttributes.AnsiClass | TypeAttributes.AutoClass, typeof(MulticastDelegate)); |
92 | 103 | ||
93 | ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor( | 104 | ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor( |
94 | MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public, | 105 | MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public, |