Fix monotouch bootstrap.
authorRodrigo Kumpera <kumpera@gmail.com>
Wed, 15 Sep 2010 12:56:04 +0000 (09:56 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 15 Sep 2010 12:58:17 +0000 (09:58 -0300)
* Type.cs (GetTypeCodeImpl): If the type is a TypeBuilder
call into specific code.

* TypeBuilder.cs (GetTypeCodeInternal): New method that
handles enums correctly.

This change is required because calling into the runtime
with incomplete TypeBuilders cause the runtime to crash.

mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System/Type.cs

index 9b8144996964ffc729a9224fc8e05878fe148773..3115d008a6c86f3000a9edf465f8e316e2561bac 100644 (file)
@@ -1897,6 +1897,20 @@ namespace System.Reflection.Emit
                                return res;
                }
 
+               internal TypeCode GetTypeCodeInternal () {
+                       if (parent == pmodule.assemblyb.corlib_enum_type) {
+                               for (int i = 0; i < num_fields; ++i) {
+                                       FieldBuilder f = fields [i];
+                                       if (!f.IsStatic)
+                                               return Type.GetTypeCode (f.FieldType);
+                               }
+                               throw new InvalidOperationException ("Enum basetype field not defined");
+                       } else {
+                               return Type.GetTypeCodeInternal (this);
+                       }
+               }
+
+
                void _TypeBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
                {
                        throw new NotImplementedException ();
index b45fcba8d228e2d752c0f0f02d88aca0637a5111..cd207e99347e9369024eda065b984684b483200d 100644 (file)
@@ -686,6 +686,8 @@ namespace System {
                        Type type = this;
                        if (type is MonoType)
                                return GetTypeCodeInternal (type);
+                       if (type is TypeBuilder)
+                               return ((TypeBuilder)type).GetTypeCodeInternal ();
 
                        type = type.UnderlyingSystemType;