IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
DynamicMethodUtil.cs
Go to the documentation of this file.
1using System;
2using System.Reflection;
3using System.Reflection.Emit;
4using System.Security;
5
6namespace IKVM.Runtime
7{
8
9#if IMPORTER == false && EXPORTER == false
10
14 static class DynamicMethodUtil
15 {
16
26 [SecuritySafeCritical]
27 internal static DynamicMethod Create(string name, Type owner, bool nonPublic, Type returnType, Type[] paramTypes)
28 {
29#if FIRST_PASS
30 throw new NotImplementedException();
31#else
32#if NETFRAMEWORK
33 return CreateFramework(name, owner, nonPublic, returnType, paramTypes);
34#else
35 return CreateCore(name, owner, nonPublic, returnType, paramTypes);
36#endif
37#endif
38 }
39
40
41#if NETFRAMEWORK
42
43 static readonly Lazy<Module> dynamicModule = new Lazy<Module>(CreateDynamicModule, true);
44
49 static Module CreateDynamicModule()
50 {
51 var name = RuntimeUtil.IsMono ? "__DynamicMethodModule" : "__<DynamicMethodModule>";
52 var dynamicAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.RunAndCollect);
53 return dynamicAssembly.DefineDynamicModule(name);
54 }
55
65 static DynamicMethod CreateFramework(string name, Type owner, bool nonPublic, Type returnType, Type[] paramTypes)
66 {
67 try
68 {
69 return new DynamicMethod(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, paramTypes, dynamicModule.Value, true);
70 }
71 catch (SecurityException)
72 {
73 return new DynamicMethod(name, returnType, paramTypes, nonPublic);
74 }
75 }
76
77#else
78
88 static DynamicMethod CreateCore(string name, Type owner, bool nonPublic, Type returnType, Type[] paramTypes)
89 {
90 if (ReflectUtil.CanOwnDynamicMethod(owner))
91 return new DynamicMethod(name, returnType, paramTypes, owner);
92 else
93 return new DynamicMethod(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, paramTypes, owner.Module, true);
94 }
95
96#endif
97
98 }
99
100#endif
101
102}
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.AssemblyName AssemblyName
Provides utilities for working with dynamic methods.