ParameterBuilderTest.cs 1.3 KB

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