3 using System
.Reflection
;
4 using System
.Reflection
.Emit
;
8 var dyn
= DefineDynamicAssembly (AppDomain
.CurrentDomain
);
9 var core
= TriggerLoadingSystemCore ();
10 var asm
= AppDomain
.CurrentDomain
.GetAssemblies ();
12 if (asm
[0] != typeof (object).Assembly
) {
13 Console
.WriteLine ("first assembly must be mscorlib, but it was {0}", asm
[0]);
17 if (asm
[1] != typeof (Driver
).Assembly
) {
18 Console
.WriteLine ("second assembly must be test assembly, but it was {0}", asm
[1]);
23 Console
.WriteLine ("third assembly must be SRE, but it was {0}", asm
[2]);
27 if (asm
[3] != core
) {
28 Console
.WriteLine ("last assembly must be System.Core, but it was {0}", asm
[3]);
35 [System
.Runtime
.CompilerServices
.MethodImpl(System
.Runtime
.CompilerServices
.MethodImplOptions
.NoInlining
)]
36 static Assembly
TriggerLoadingSystemCore ()
38 int[] x
= new int[] { 1,2,3}
;
40 return typeof (Enumerable
).Assembly
;
44 static Assembly
DefineDynamicAssembly (AppDomain domain
)
46 AssemblyName assemblyName
= new AssemblyName ();
47 assemblyName
.Name
= "MyDynamicAssembly";
49 AssemblyBuilder assemblyBuilder
= domain
.DefineDynamicAssembly (assemblyName
, AssemblyBuilderAccess
.Run
);
50 ModuleBuilder moduleBuilder
= assemblyBuilder
.DefineDynamicModule ("MyDynamicModule");
51 TypeBuilder typeBuilder
= moduleBuilder
.DefineType ("MyDynamicType", TypeAttributes
.Public
);
52 ConstructorBuilder constructorBuilder
= typeBuilder
.DefineConstructor (MethodAttributes
.Public
, CallingConventions
.Standard
, null);
53 ILGenerator ilGenerator
= constructorBuilder
.GetILGenerator ();
54 ilGenerator
.EmitWriteLine ("MyDynamicType instantiated!");
55 ilGenerator
.Emit (OpCodes
.Ret
);
56 typeBuilder
.CreateType ();
57 return assemblyBuilder
;