2007-05-16 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
index e5eaaad1cb32abab714d73e58a21f4589e420204..141046081c0961a2d49960dc6f8a5df99559ae05 100644 (file)
@@ -133,6 +133,7 @@ namespace System.Reflection.Emit {
                                System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
                        }
                        pmodule = mb;
+
                        // skip .<Module> ?
                        table_idx = mb.get_next_table_index (this, 0x02, true);
                        setup_internal_class (this);
@@ -173,25 +174,7 @@ namespace System.Reflection.Emit {
 
                public override Type UnderlyingSystemType {
                        get {
-
-                               // Return this as requested by Zoltan.
-                               
                                return this;
-
-#if false
-                               // Dont know what to do with the rest, should be killed:
-                               // See bug: 75008.
-                               //
-                               ////// This should return the type itself for non-enum types but 
-                               ////// that breaks mcs.
-                               if (fields != null) {
-                                       foreach (FieldBuilder f in fields) {
-                                               if ((f != null) && (f.Attributes & FieldAttributes.Static) == 0)
-                                                       return f.FieldType;
-                                       }
-                               }
-                               throw new InvalidOperationException ("Underlying type information on enumeration is not specified.");
-#endif
                        }
                }
 
@@ -681,6 +664,10 @@ namespace System.Reflection.Emit {
                        if (created != null)
                                return created;
 
+                       if (!IsInterface && (parent == null) && (this != pmodule.assemblyb.corlib_object_type) && (FullName != "<Module>")) {
+                               SetParent (pmodule.assemblyb.corlib_object_type);
+                       }
+
                        create_generic_class ();
 
                        // Fire TypeResolve events for fields whose type is an unfinished
@@ -902,6 +889,9 @@ namespace System.Reflection.Emit {
                }
 
                public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
+                       if (created != null)
+                               return created.GetFields (bindingAttr);
+
                        if (fields == null)
                                return new FieldInfo [0];
                        ArrayList l = new ArrayList ();
@@ -1372,7 +1362,7 @@ namespace System.Reflection.Emit {
 
                        if (parentType == null && (attrs & TypeAttributes.Interface) == 0)
                                throw new ArgumentNullException ("parentType");
-                       
+
                        parent = parentType;
                        // will just set the parent-related bits if called a second time
                        setup_internal_class (this);