1 // ParameterBuilderTest.cs
2 //
3 // Author: Gleb Golubitsky <sectoid@gnolltech.org>
4 //
5 // (c) 2012 Gleb Golubitsky
6 //
7 using System;
8 using System.Reflection.Emit;
9 using System.Reflection;
10 using NUnit.Framework;
11 
12 namespace MonoTests.System.Reflection.Emit
13 {
14 	/// <summary>
15 	/// A test fixture for System.Reflection.Emit.ParameterBuilder class
16 	/// </summary>
17 	[TestFixture]
18 	public class ParameterBuilderTest
19 	{
20 		[Test]
21 		/// <summary>
22 		/// Unit test for a problem in ParameterBuilder.SetConstant
23 		/// method. The problem is described at bug #3912.
24 		/// (https://bugzilla.xamarin.com/show_bug.cgi?id=3912)
25 		/// </summary>
ParameterBuilderSetConstant_Bug3912()26 		public void ParameterBuilderSetConstant_Bug3912 ()
27 		{
28 			var aName = new AssemblyName("DynamicAssemblyExample");
29 			var ab = AppDomain.CurrentDomain
30 				.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
31 
32 			var mb = ab.DefineDynamicModule(aName.Name);
33 
34 			var eb = mb.DefineEnum("TestEnum",
35 				TypeAttributes.Public,
36 				typeof(int));
37 
38 			eb.DefineLiteral("Low", 0);
39 			eb.DefineLiteral("High", 1);
40 
41 			var tb = mb.DefineType("MyDynamicType", TypeAttributes.Public);
42 
43 			var hello = tb.DefineMethod("Fail",
44 				MethodAttributes.Public,
45 				typeof(void),
46 				new [] { eb, });
47 			var builder = hello.DefineParameter(1, ParameterAttributes.In, "failParam");
48 			builder.SetConstant(1);
49 		}
50 	}
51 }
52