2010-06-21 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / sighelpermod.cs
blob261a9a1bb58432f982c578d118f9720f814163af
1 //
2 // Not sure how we could automate this test, for now you have to look at the
3 // generated output (b.dll) and see that the signature for the method called
4 // (the one with no name :-) looks like this:
5 //
6 // call instance int32 (bool,
7 // class System.String modreq([mscorlib]System.Runtime.CompilerServices.IsBoxed),
8 // unsigned int8 modopt([mscorlib]System.Runtime.CompilerServices.IsConst),
9 // int32 modopt([mscorlib]System.Runtime.CompilerServices.IsConst),
10 // int64 modopt([mscorlib]System.Runtime.CompilerServices.IsConst))
13 using System;
14 using System.Reflection;
15 using System.Reflection.Emit;
16 using System.Threading;
18 public class EmitHelloWorld{
19 static void Main(string[] args)
21 AssemblyName an = new AssemblyName();
22 an.Name = "HelloWorld";
23 AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
24 ModuleBuilder module = ab.DefineDynamicModule("b.dll");
25 TypeBuilder tb = module.DefineType("type", TypeAttributes.Public | TypeAttributes.Class);
26 MethodBuilder mb = tb.DefineMethod("test",
27 MethodAttributes.HideBySig | MethodAttributes.Static |
28 MethodAttributes.Public, typeof(void), null);
29 ILGenerator ig = mb.GetILGenerator();
32 // This is the actual test:
33 // Generate a method signature that contains modopts and modreqs
34 // and call that. It has no name or anything, not sure how this
35 // is actually used, but we at least generate the stuff
37 SignatureHelper sh = SignatureHelper.GetMethodSigHelper (module, CallingConventions.HasThis, typeof(int));
38 sh.AddArgument (typeof (bool));
39 Type [] req = new Type [] { typeof (System.Runtime.CompilerServices.IsBoxed) };
40 sh.AddArgument (typeof (string), req, null);
41 Type [] opt = new Type [] { typeof (System.Runtime.CompilerServices.IsConst) };
42 sh.AddArgument (typeof (byte), null, opt);
43 sh.AddArgument (typeof (int), null, opt);
44 sh.AddArgument (typeof (long), null, opt);
45 ig.Emit (OpCodes.Call, sh);
47 ig.Emit(OpCodes.Ret);
49 tb.CreateType();
51 ab.Save ("b.dll");