X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Reflection.Emit%2FTypeBuilder.cs;h=c385605b22924a8ce021e02769ff5f10193b5dd7;hb=3b44a4eb76cd8b949c659e6c004e3b8b1ddd883a;hp=82bc20c3ba7c5047bfd99bf627214c289407b3c0;hpb=75df74a96c33af7a99e16e4281272f1b67334a48;p=mono.git diff --git a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs index 82bc20c3ba7..c385605b229 100644 --- a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs @@ -3,6 +3,7 @@ // // Author: // Paolo Molaro (lupus@ximian.com) +// Marek Safar (marek.safar@gmail.com) // // (C) 2001 Ximian, Inc. http://www.ximian.com // @@ -132,6 +133,7 @@ namespace System.Reflection.Emit { System.Array.Copy (interfaces, this.interfaces, interfaces.Length); } pmodule = mb; + // skip . ? table_idx = mb.get_next_table_index (this, 0x02, true); setup_internal_class (this); @@ -170,28 +172,9 @@ namespace System.Reflection.Emit { return false; }*/ - [MonoTODO] 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 != "")) { + SetParent (pmodule.assemblyb.corlib_object_type); + } + create_generic_class (); // Fire TypeResolve events for fields whose type is an unfinished @@ -864,6 +851,9 @@ namespace System.Reflection.Emit { } public override FieldInfo GetField( string name, BindingFlags bindingAttr) { + if (created != null) + return created.GetField (name, bindingAttr); + if (fields == null) return null; @@ -902,6 +892,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 (); @@ -1151,8 +1144,15 @@ namespace System.Reflection.Emit { throw not_supported (); } - protected override bool HasElementTypeImpl () { + protected override bool HasElementTypeImpl () + { +#if NET_2_0 + // a TypeBuilder can never represent an array, pointer + if (!is_created) + return false; +#else check_created (); +#endif return created.HasElementType; } @@ -1290,6 +1290,8 @@ namespace System.Reflection.Emit { } else if (attrname == "System.Runtime.InteropServices.ComImportAttribute") { attrs |= TypeAttributes.Import; return; + } else if (attrname == "System.Security.SuppressUnmanagedCodeSecurityAttribute") { + attrs |= TypeAttributes.HasSecurity; } if (cattrs != null) { @@ -1343,18 +1345,22 @@ namespace System.Reflection.Emit { static int UnmanagedDataCount = 0; - public FieldBuilder DefineUninitializedData( string name, int size, FieldAttributes attributes) { + public FieldBuilder DefineUninitializedData( string name, int size, FieldAttributes attributes) + { check_name ("name", name); if ((size <= 0) || (size > 0x3f0000)) throw new ArgumentException ("size", "Data size must be > 0 and < 0x3f0000"); check_not_created (); - string s = "$ArrayType$"+UnmanagedDataCount.ToString(); - UnmanagedDataCount++; - TypeBuilder datablobtype = DefineNestedType (s, - TypeAttributes.NestedPrivate|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed, - pmodule.assemblyb.corlib_value_type, null, PackingSize.Size1, size); - datablobtype.CreateType (); + string typeName = "$ArrayType$" + size; + Type datablobtype = pmodule.GetRegisteredType (fullname + "+" + typeName); + if (datablobtype == null) { + TypeBuilder tb = DefineNestedType (typeName, + TypeAttributes.NestedPrivate|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed, + pmodule.assemblyb.corlib_value_type, null, PackingSize.Size1, size); + tb.CreateType (); + datablobtype = tb; + } return DefineField (name, datablobtype, attributes|FieldAttributes.Static|FieldAttributes.HasFieldRVA); } @@ -1368,7 +1374,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);