2003-10-03 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Fri, 3 Oct 2003 13:37:56 +0000 (13:37 -0000)
committerZoltan Varga <vargaz@gmail.com>
Fri, 3 Oct 2003 13:37:56 +0000 (13:37 -0000)
* TypeBuilder.cs (CreateType): Fire TypeResolve events for unfinished
nested value types. Fixes #47022.

svn path=/trunk/mcs/; revision=18553

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

index 39a1ae24c0c86be7273a11e2467ba5957910c05c..1dd0080d947188c2b9b969df2712371fdc29aae1 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-03  Zoltan Varga  <vargaz@freemail.hu>
+
+       * TypeBuilder.cs (CreateType): Fire TypeResolve events for unfinished 
+       nested value types. Fixes #47022.
+
 2003-09-29  Zoltan Varga  <vargaz@freemail.hu>
 
        * TypeBuilder.cs: Really fix #48695.
index e1956498c86f43c2e4025896534eb4048209fa6d..aa4ae659cbb4c59a4ab7814629b4c54a33f93c4b 100644 (file)
@@ -477,11 +477,42 @@ namespace System.Reflection.Emit {
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern Type create_runtime_class (TypeBuilder tb);
+
+               private bool is_nested_in (Type t) {
+                       while (t != null) {
+                               if (t == this)
+                                       return true;
+                               else
+                                       t = t.DeclaringType;
+                       }
+                       return false;
+               }
                
                public Type CreateType() {
                        /* handle nesting_type */
                        if (is_created)
                                throw not_after_created ();
+
+                       // Fire TypeResolve events for fields whose type is an unfinished
+                       // value type.
+                       if (fields != null) {
+                               foreach (FieldBuilder fb in fields) {
+                                       Type ft = fb.FieldType;
+                                       if (!fb.IsStatic && (ft is TypeBuilder) && ft.IsValueType && (ft != this) && is_nested_in (ft)) {
+                                               TypeBuilder tb = (TypeBuilder)ft;
+                                               if (!tb.is_created) {
+                                                       AppDomain.CurrentDomain.DoTypeResolve (tb);
+                                                       if (!tb.is_created) {
+                                                               // FIXME: We should throw an exception here,
+                                                               // but mcs expects that the type is created
+                                                               // even if the exception is thrown
+                                                               //throw new TypeLoadException ("Could not load type " + tb);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
                        if (methods != null) {
                                foreach (MethodBuilder method in methods) {
                                        method.fixup ();
@@ -498,7 +529,7 @@ namespace System.Reflection.Emit {
                                foreach (ConstructorBuilder ctor in ctors) 
                                        ctor.fixup ();
                        }
-                       
+
                        created = create_runtime_class (this);
                        if (created != null)
                                return created;