[Mono-bugs] [Bug 58657][Blo] New - EnumBuilder does not work.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 18 May 2004 12:42:47 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by rbo@acm.org.

http://bugzilla.ximian.com/show_bug.cgi?id=58657

--- shadow/58657	2004-05-18 12:42:47.000000000 -0400
+++ shadow/58657.tmp.26621	2004-05-18 12:42:47.000000000 -0400
@@ -0,0 +1,82 @@
+Bug#: 58657
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rbo@acm.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: EnumBuilder does not work.
+
+Description of Problem:
+
+System.Reflection.Emit.EnumBuilder does not work.
+
+
+Steps to reproduce the problem:
+namespace MonoEmitTestFixtures
+{
+	using System;
+	using System.Reflection;
+	using System.Reflection.Emit;
+	using NUnit.Framework;
+	
+	[TestFixture]
+	public class EnumTestFixture
+	{
+		Assembly _assembly;
+		
+		[TestFixtureSetUp]
+		public void SetUpFixture()
+		{
+			AssemblyName name = new AssemblyName();
+			name.Name = "DynamicAssembly";
+
+			AssemblyBuilder builder = 
+AppDomain.CurrentDomain.DefineDynamicAssembly(name, 
+AssemblyBuilderAccess.Save);
+			ModuleBuilder module = builder.DefineDynamicModule
+(name.Name, "DynamicAssembly.dll");
+
+			EnumBuilder enumBuilder = module.DefineEnum
+("SimpleEnum", TypeAttributes.Public, typeof(int));
+			enumBuilder.DefineLiteral("One", 1);
+			enumBuilder.DefineLiteral("Two", 2);
+			enumBuilder.CreateType();
+
+			builder.Save("DynamicAssembly.dll");
+
+			_assembly = Assembly.LoadFrom
+("DynamicAssembly.dll");
+		}
+		
+		[Test]
+		public void EnumWasCorrectlyEmitted()
+		{
+			Type[] types = _assembly.GetTypes();
+			Assert.AreEqual(1, types.Length);
+			
+			Type type = types[0];
+			Assert.IsTrue(type.IsEnum, "Type.IsEnum");
+			Assert.AreEqual("SimpleEnum", 
+type.Name, "Type.Name");
+			Assert.IsTrue(type.IsPublic);
+			
+			string[] names = Enum.GetNames(type);
+			Assert.AreEqual("One", names[0]);
+			Assert.AreEqual("Two", names[1]);
+			Assert.AreEqual(1, type.GetField("One").GetValue
+(null));
+			Assert.AreEqual(2, type.GetField("Two").GetValue
+(null));
+		}
+	}
+}