Mon Sep 9 17:31:12 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
1 //
2 // System.Reflection.Emit/TypeBuilder.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11 using System.Reflection;
12 using System.Reflection.Emit;
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 using System.Globalization;
16 using System.Collections;
17 using System.Security;
18 using System.Security.Permissions;
19
20 namespace System.Reflection.Emit {
21         public sealed class TypeBuilder : Type {
22         private string tname;
23         private string nspace;
24         private Type parent;
25         private Type nesting_type;
26         private Type[] interfaces;
27         private MethodBuilder[] methods;
28         private ConstructorBuilder[] ctors;
29         private PropertyBuilder[] properties;
30         private FieldBuilder[] fields;
31         private EventBuilder[] events;
32         private CustomAttributeBuilder[] cattrs;
33         internal TypeBuilder[] subtypes;
34         private TypeAttributes attrs;
35         private int table_idx;
36         private ModuleBuilder pmodule;
37         private int class_size;
38         private PackingSize packing_size;
39         private Type created;
40
41         public const int UnspecifiedTypeSize = 0;
42
43                 protected override TypeAttributes GetAttributeFlagsImpl () {
44                         return attrs;
45                 }
46                 
47                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
48                 private extern void setup_internal_class (TypeBuilder tb);
49                 
50                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
51                 private extern void create_internal_class (TypeBuilder tb);
52                 
53                 internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size) {
54                         int sep_index;
55                         this.parent = parent;
56                         this.attrs = attr;
57                         this.class_size = type_size;
58                         this.packing_size = packing_size;
59                         sep_index = name.LastIndexOf('.');
60                         if (sep_index != -1) {
61                                 this.tname = name.Substring (sep_index + 1);
62                                 this.nspace = name.Substring (0, sep_index);
63                         } else {
64                                 this.tname = name;
65                                 this.nspace = "";
66                         }
67                         if (interfaces != null) {
68                                 this.interfaces = new Type[interfaces.Length];
69                                 System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
70                         }
71                         pmodule = mb;
72                         // skip .<Module> ?
73                         table_idx = mb.get_next_table_index (this, 0x02, true);
74                         setup_internal_class (this);
75                 }
76
77                 public override Assembly Assembly {
78                         get {return pmodule.Assembly;}
79                 }
80                 public override string AssemblyQualifiedName {
81                         get {
82                                 return FullName + ", " + Assembly.ToString();
83                         }
84                 }
85                 public override Type BaseType {
86                         get {
87                                 return parent;
88                         }
89                 }
90                 public override Type DeclaringType {get {return nesting_type;}}
91                 public override Type UnderlyingSystemType {
92                         get {
93                                 if (fields != null) {
94                                         foreach (FieldBuilder f in fields) {
95                                                 if ((f.Attributes & FieldAttributes.Static) == 0)
96                                                         return f.FieldType;
97                                         }
98                                 }
99                                 throw new InvalidOperationException (String.Format ("typebuilder: {0}", this));
100                         }
101                 }
102
103                 public override string FullName {
104                         get {
105                                 if (nesting_type != null)
106                                         return String.Concat (nesting_type.FullName, "+", tname);
107                                 if ((nspace != null) && (nspace.Length > 0))
108                                         return String.Concat (nspace, ".", tname);
109                                 return tname;
110                         }
111                 }
112         
113                 public override Guid GUID {
114                         get {return Guid.Empty;}
115                 }
116
117                 public override Module Module {
118                         get {return pmodule;}
119                 }
120                 public override string Name {
121                         get {return tname;}
122                 }
123                 public override string Namespace {
124                         get {return nspace;}
125                 }
126                 public PackingSize PackingSize {
127                         get {return packing_size;}
128                 }
129                 public override Type ReflectedType {get {return nesting_type;}}
130                 public override MemberTypes MemberType { 
131                         get {return MemberTypes.TypeInfo;}
132                 }
133
134                 [MonoTODO]
135                 public void AddDeclarativeSecurity( SecurityAction action, PermissionSet pset) {
136                         throw new NotImplementedException ();
137                 }
138
139                 public void AddInterfaceImplementation( Type interfaceType) {
140                         if (interfaces != null) {
141                                 Type[] ifnew = new Type [interfaces.Length + 1];
142                                 interfaces.CopyTo (ifnew, 0);
143                                 ifnew [interfaces.Length] = interfaceType;
144                                 interfaces = ifnew;
145                         } else {
146                                 interfaces = new Type [1];
147                                 interfaces [0] = interfaceType;
148                         }
149                 }
150
151                 [MonoTODO]
152                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
153                         throw new NotImplementedException ();
154                 }
155
156                 public override bool IsDefined( Type attributeType, bool inherit) {
157                         return false;
158                 }
159                 public override object[] GetCustomAttributes(bool inherit) {
160                         return null;
161                 }
162                 public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
163                         return null;
164                 }
165
166                 [MonoTODO]
167                 public TypeBuilder DefineNestedType (string name) {
168                         // FIXME: LAMESPEC: what other attributes should we use here as default?
169                         return DefineNestedType (name, TypeAttributes.Public, pmodule.assemblyb.corlib_object_type, null);
170                 }
171
172                 public TypeBuilder DefineNestedType (string name, TypeAttributes attr) {
173                         return DefineNestedType (name, attr, pmodule.assemblyb.corlib_object_type, null);
174                 }
175
176                 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent) {
177                         return DefineNestedType (name, attr, parent, null);
178                 }
179
180                 private TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packsize, int typesize) {
181                         TypeBuilder res = new TypeBuilder (pmodule, name, attr, parent, interfaces, packsize, typesize);
182                         res.nesting_type = this;
183                         if (subtypes != null) {
184                                 TypeBuilder[] new_types = new TypeBuilder [subtypes.Length + 1];
185                                 System.Array.Copy (subtypes, new_types, subtypes.Length);
186                                 new_types [subtypes.Length] = res;
187                                 subtypes = new_types;
188                         } else {
189                                 subtypes = new TypeBuilder [1];
190                                 subtypes [0] = res;
191                         }
192                         return res;
193                 }
194
195                 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces) {
196                         return DefineNestedType (name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
197                 }
198
199                 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, int typesize) {
200                         return DefineNestedType (name, attr, parent, null, PackingSize.Unspecified, typesize);
201                 }
202
203                 public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, PackingSize packsize) {
204                         return DefineNestedType (name, attr, parent, null, packsize, UnspecifiedTypeSize);
205                 }
206
207                 public ConstructorBuilder DefineConstructor( MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
208                         ConstructorBuilder cb = new ConstructorBuilder (this, attributes, callingConvention, parameterTypes);
209                         if (ctors != null) {
210                                 ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
211                                 System.Array.Copy (ctors, new_ctors, ctors.Length);
212                                 new_ctors [ctors.Length] = cb;
213                                 ctors = new_ctors;
214                         } else {
215                                 ctors = new ConstructorBuilder [1];
216                                 ctors [0] = cb;
217                         }
218                         return cb;
219                 }
220
221                 public ConstructorBuilder DefineDefaultConstructor( MethodAttributes attributes) {
222                         return DefineConstructor (attributes, CallingConventions.Standard, null);
223                 }
224
225                 public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
226                         return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
227                 }
228
229                 private void append_method (MethodBuilder mb) {
230                         if (methods != null) {
231                                 MethodBuilder[] new_methods = new MethodBuilder [methods.Length+1];
232                                 System.Array.Copy (methods, new_methods, methods.Length);
233                                 new_methods [methods.Length] = mb;
234                                 methods = new_methods;
235                         } else {
236                                 methods = new MethodBuilder [1];
237                                 methods [0] = mb;
238                         }
239                 }
240
241                 public MethodBuilder DefineMethod( string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
242                         MethodBuilder res = new MethodBuilder (this, name, attributes, callingConvention, returnType, parameterTypes);
243                         append_method (res);
244                         return res;
245                 }
246
247                 public MethodBuilder DefinePInvokeMethod (string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
248                         MethodBuilder res = new MethodBuilder (this, name, attributes, callingConvention, returnType, parameterTypes,
249                                 dllName, entryName, nativeCallConv, nativeCharSet);
250                         append_method (res);
251                         return res;
252                 }
253
254                 public MethodBuilder DefinePInvokeMethod (string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet) {
255                         return DefinePInvokeMethod (name, dllName, name, attributes, callingConvention, returnType, parameterTypes,
256                                 nativeCallConv, nativeCharSet);
257                 }
258
259                 public void DefineMethodOverride( MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) {
260                         if (methodInfoBody is MethodBuilder) {
261                                 MethodBuilder mb = (MethodBuilder)methodInfoBody;
262                                 mb.set_override (methodInfoDeclaration);
263                         }
264                 }
265
266                 public FieldBuilder DefineField( string fieldName, Type type, FieldAttributes attributes) {
267                         FieldBuilder res = new FieldBuilder (this, fieldName, type, attributes);
268                         if (fields != null) {
269                                 FieldBuilder[] new_fields = new FieldBuilder [fields.Length+1];
270                                 System.Array.Copy (fields, new_fields, fields.Length);
271                                 new_fields [fields.Length] = res;
272                                 fields = new_fields;
273                         } else {
274                                 fields = new FieldBuilder [1];
275                                 fields [0] = res;
276                                 create_internal_class (this);
277                         }
278                         return res;
279                 }
280
281                 public PropertyBuilder DefineProperty( string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes) {
282                         PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, parameterTypes);
283
284                         if (properties != null) {
285                                 PropertyBuilder[] new_properties = new PropertyBuilder [properties.Length+1];
286                                 System.Array.Copy (properties, new_properties, properties.Length);
287                                 new_properties [properties.Length] = res;
288                                 properties = new_properties;
289                         } else {
290                                 properties = new PropertyBuilder [1];
291                                 properties [0] = res;
292                         }
293                         return res;
294                 }
295
296                 [MonoTODO]
297                 public ConstructorBuilder DefineTypeInitializer() {
298                         throw new NotImplementedException ();
299                 }
300
301                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
302                 private extern Type create_runtime_class (TypeBuilder tb);
303                 
304                 public Type CreateType() {
305                         /* handle nesting_type */
306                         if (created != null)
307                                 throw new InvalidOperationException ("type already created");
308                         if (methods != null) {
309                                 foreach (MethodBuilder method in methods) {
310                                         method.fixup ();
311                                 }
312                         }
313                         if (ctors != null) {
314                                 foreach (ConstructorBuilder ctor in ctors) {
315                                         ctor.fixup ();
316                                 }
317                         }
318                         created = create_runtime_class (this);
319                         if (created != null)
320                                 return created;
321                         return this;
322                 }
323
324                 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr) {
325                         if (ctors == null)
326                                 return new ConstructorInfo [0];
327                         ArrayList l = new ArrayList ();
328                         bool match;
329                         MethodAttributes mattrs;
330                         
331                         foreach (ConstructorBuilder c in ctors) {
332                                 match = false;
333                                 mattrs = c.Attributes;
334                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
335                                         if ((bindingAttr & BindingFlags.Public) != 0)
336                                                 match = true;
337                                 } else {
338                                         if ((bindingAttr & BindingFlags.NonPublic) != 0)
339                                                 match = true;
340                                 }
341                                 if (!match)
342                                         continue;
343                                 match = false;
344                                 if ((mattrs & MethodAttributes.Static) != 0) {
345                                         if ((bindingAttr & BindingFlags.Static) != 0)
346                                                 match = true;
347                                 } else {
348                                         if ((bindingAttr & BindingFlags.Instance) != 0)
349                                                 match = true;
350                                 }
351                                 if (!match)
352                                         continue;
353                                 l.Add (c);
354                         }
355                         ConstructorInfo[] result = new ConstructorInfo [l.Count];
356                         l.CopyTo (result);
357                         return result;
358                 }
359
360                 public override Type GetElementType () { return null; }
361
362                 [MonoTODO]
363                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr) {
364                         throw new NotImplementedException ();
365                 }
366
367                 public override EventInfo[] GetEvents (BindingFlags bindingAttr) {
368                         return new EventInfo [0];
369                 }
370
371                 [MonoTODO]
372                 public override FieldInfo GetField( string name, BindingFlags bindingAttr) {
373                         //FIXME
374                         throw new NotImplementedException ();
375                 }
376
377                 public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
378                         if (fields == null)
379                                 return new FieldInfo [0];
380                         ArrayList l = new ArrayList ();
381                         bool match;
382                         FieldAttributes mattrs;
383                         
384                         foreach (FieldInfo c in fields) {
385                                 match = false;
386                                 mattrs = c.Attributes;
387                                 if ((mattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
388                                         if ((bindingAttr & BindingFlags.Public) != 0)
389                                                 match = true;
390                                 } else {
391                                         if ((bindingAttr & BindingFlags.NonPublic) != 0)
392                                                 match = true;
393                                 }
394                                 if (!match)
395                                         continue;
396                                 match = false;
397                                 if ((mattrs & FieldAttributes.Static) != 0) {
398                                         if ((bindingAttr & BindingFlags.Static) != 0)
399                                                 match = true;
400                                 } else {
401                                         if ((bindingAttr & BindingFlags.Instance) != 0)
402                                                 match = true;
403                                 }
404                                 if (!match)
405                                         continue;
406                                 l.Add (c);
407                         }
408                         FieldInfo[] result = new FieldInfo [l.Count];
409                         l.CopyTo (result);
410                         return result;
411                 }
412
413                 [MonoTODO]
414                 public override Type GetInterface (string name, bool ignoreCase) {
415                         throw new NotImplementedException ();
416                 }
417                 
418                 public override Type[] GetInterfaces () {
419                         if (interfaces != null) {
420                                 Type[] ret = new Type [interfaces.Length];
421                                 interfaces.CopyTo (ret, 0);
422                                 return ret;
423                         } else {
424                                 return Type.EmptyTypes;
425                         }
426                 }
427
428                 [MonoTODO]
429                 public override MemberInfo[] GetMembers( BindingFlags bindingAttr) {
430                         // FIXME
431                         throw new NotImplementedException ();
432                 }
433
434                 public override MethodInfo[] GetMethods (BindingFlags bindingAttr) {
435                         if (methods == null)
436                                 return new MethodInfo [0];
437                         ArrayList l = new ArrayList ();
438                         bool match;
439                         MethodAttributes mattrs;
440
441                         foreach (MethodInfo c in methods) {
442                                 match = false;
443                                 mattrs = c.Attributes;
444                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
445                                         if ((bindingAttr & BindingFlags.Public) != 0)
446                                                 match = true;
447                                 } else {
448                                         if ((bindingAttr & BindingFlags.NonPublic) != 0)
449                                                 match = true;
450                                 }
451                                 if (!match)
452                                         continue;
453                                 match = false;
454                                 if ((mattrs & MethodAttributes.Static) != 0) {
455                                         if ((bindingAttr & BindingFlags.Static) != 0)
456                                                 match = true;
457                                 } else {
458                                         if ((bindingAttr & BindingFlags.Instance) != 0)
459                                                 match = true;
460                                 }
461                                 if (!match)
462                                         continue;
463                                 l.Add (c);
464                         }
465                         MethodInfo[] result = new MethodInfo [l.Count];
466                         l.CopyTo (result);
467                         return result;
468                 }
469
470                 [MonoTODO]
471                 protected override MethodInfo GetMethodImpl( string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
472                         // FIXME
473                         throw new NotImplementedException ();
474                 }
475                 
476                 [MonoTODO]
477                 public override Type GetNestedType( string name, BindingFlags bindingAttr) {
478                         // FIXME
479                         throw new NotImplementedException ();
480                 }
481
482                 public override Type[] GetNestedTypes (BindingFlags bindingAttr) {
483                         bool match;
484                         ArrayList result = new ArrayList ();
485                 
486                         if (subtypes == null)
487                                 return Type.EmptyTypes;
488                         foreach (TypeBuilder t in subtypes) {
489                                 match = false;
490                                 if ((t.attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic) {
491                                         if ((bindingAttr & BindingFlags.Public) != 0)
492                                                 match = true;
493                                 } else {
494                                         if ((bindingAttr & BindingFlags.NonPublic) != 0)
495                                                 match = true;
496                                 }
497                                 if (!match)
498                                         continue;
499                                 result.Add (t);
500                         }
501                         Type[] r = new Type [result.Count];
502                         result.CopyTo (r);
503                         return r;
504                 }
505
506                 public override PropertyInfo[] GetProperties( BindingFlags bindingAttr) {
507                         if (properties == null)
508                                 return new PropertyInfo [0];
509                         ArrayList l = new ArrayList ();
510                         bool match;
511                         MethodAttributes mattrs;
512                         MethodInfo accessor;
513                         
514                         foreach (PropertyInfo c in properties) {
515                                 match = false;
516                                 accessor = c.GetGetMethod (true);
517                                 if (accessor == null)
518                                         accessor = c.GetSetMethod (true);
519                                 if (accessor == null)
520                                         continue;
521                                 mattrs = accessor.Attributes;
522                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
523                                         if ((bindingAttr & BindingFlags.Public) != 0)
524                                                 match = true;
525                                 } else {
526                                         if ((bindingAttr & BindingFlags.NonPublic) != 0)
527                                                 match = true;
528                                 }
529                                 if (!match)
530                                         continue;
531                                 match = false;
532                                 if ((mattrs & MethodAttributes.Static) != 0) {
533                                         if ((bindingAttr & BindingFlags.Static) != 0)
534                                                 match = true;
535                                 } else {
536                                         if ((bindingAttr & BindingFlags.Instance) != 0)
537                                                 match = true;
538                                 }
539                                 if (!match)
540                                         continue;
541                                 l.Add (c);
542                         }
543                         PropertyInfo[] result = new PropertyInfo [l.Count];
544                         l.CopyTo (result);
545                         return result;
546                 }
547                 
548                 [MonoTODO]
549                 protected override PropertyInfo GetPropertyImpl( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
550                         // FIXME
551                         throw new NotImplementedException ();
552                 }
553
554                 protected override bool HasElementTypeImpl () {
555                         return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
556                 }
557
558                 [MonoTODO]
559                 public override object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) {
560                         // FIXME
561                         throw new NotImplementedException ();
562                 }
563
564                 protected override bool IsArrayImpl () {
565                         return type_is_subtype_of (this, typeof (System.Array), false);
566                 }
567                 protected override bool IsByRefImpl () {
568                         // FIXME
569                         return false;
570                 }
571                 protected override bool IsCOMObjectImpl () {
572                         return false;
573                 }
574                 protected override bool IsPointerImpl () {
575                         // FIXME
576                         return false;
577                 }
578                 protected override bool IsPrimitiveImpl () {
579                         // FIXME
580                         return false;
581                 }
582                 protected override bool IsValueTypeImpl () {
583                         return ((type_is_subtype_of (this, pmodule.assemblyb.corlib_value_type, false) || type_is_subtype_of (this, typeof(System.ValueType), false)) &&
584                                 this != pmodule.assemblyb.corlib_value_type &&
585                                 this != pmodule.assemblyb.corlib_enum_type);
586                 }
587                 
588                 public override RuntimeTypeHandle TypeHandle { get { return _impl; } }
589
590                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
591                         string attrname = customBuilder.Ctor.ReflectedType.FullName;
592                         if (attrname == "System.Runtime.InteropServices.StructLayoutAttribute") {
593                                 byte[] data = customBuilder.Data;
594                                 int layout_kind; /* the (stupid) ctor takes a short or an int ... */
595                                 layout_kind = (int)data [2];
596                                 layout_kind |= ((int)data [3]) << 8;
597                                 attrs &= ~TypeAttributes.LayoutMask;
598                                 switch ((LayoutKind)layout_kind) {
599                                 case LayoutKind.Auto:
600                                         attrs |= TypeAttributes.AutoLayout;
601                                         break;
602                                 case LayoutKind.Explicit:
603                                         attrs |= TypeAttributes.ExplicitLayout;
604                                         break;
605                                 case LayoutKind.Sequential:
606                                         attrs |= TypeAttributes.SequentialLayout;
607                                         break;
608                                 default:
609                                         // we should ignore it since it can be any value anyway...
610                                         throw new Exception ("Error in customattr");
611                                 }
612                                 string first_type_name = customBuilder.Ctor.GetParameters()[0].ParameterType.FullName;
613                                 int pos = 6;
614                                 if (first_type_name == "System.Int16")
615                                         pos = 4;
616                                 int nnamed = (int)data [pos++];
617                                 nnamed |= ((int)data [pos++]) << 8;
618                                 for (int i = 0; i < nnamed; ++i) {
619                                         byte named_type = data [pos++];
620                                         byte type = data [pos++];
621                                         int len = CustomAttributeBuilder.decode_len (data, pos, out pos);
622                                         string named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
623                                         pos += len;
624                                         /* all the fields are integers in StructLayout */
625                                         int value = (int)data [pos++];
626                                         value |= ((int)data [pos++]) << 8;
627                                         value |= ((int)data [pos++]) << 16;
628                                         value |= ((int)data [pos++]) << 24;
629                                         switch (named_name) {
630                                         case "CharSet":
631                                                 switch ((CharSet)value) {
632                                                 case CharSet.None:
633                                                 case CharSet.Ansi:
634                                                         break;
635                                                 case CharSet.Unicode:
636                                                         attrs |= TypeAttributes.UnicodeClass;
637                                                         break;
638                                                 case CharSet.Auto:
639                                                         attrs |= TypeAttributes.AutoClass;
640                                                         break;
641                                                 default:
642                                                         break; // error out...
643                                                 }
644                                                 break;
645                                         case "Pack":
646                                                 packing_size = (PackingSize)value;
647                                                 break;
648                                         case "Size":
649                                                 class_size = value;
650                                                 break;
651                                         default:
652                                                 break; // error out...
653                                         }
654                                 }
655                                 return;
656                         } else if (attrname == "System.SerializableAttribute") {
657                                 attrs |= TypeAttributes.Serializable;
658                                 return;
659                         }
660                         if (cattrs != null) {
661                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
662                                 cattrs.CopyTo (new_array, 0);
663                                 new_array [cattrs.Length] = customBuilder;
664                                 cattrs = new_array;
665                         } else {
666                                 cattrs = new CustomAttributeBuilder [1];
667                                 cattrs [0] = customBuilder;
668                         }
669                 }
670                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
671                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
672                 }
673
674                 public EventBuilder DefineEvent( string name, EventAttributes attributes, Type eventtype) {
675                         EventBuilder res = new EventBuilder (this, name, attributes, eventtype);
676                         if (events != null) {
677                                 EventBuilder[] new_events = new EventBuilder [events.Length+1];
678                                 System.Array.Copy (events, new_events, events.Length);
679                                 new_events [events.Length] = res;
680                                 events = new_events;
681                         } else {
682                                 events = new EventBuilder [1];
683                                 events [0] = res;
684                         }
685                         return res;
686                 }
687
688                 static int InitializedDataCount = 0;
689                 
690                 public FieldBuilder DefineInitializedData( string name, byte[] data, FieldAttributes attributes) {
691                         TypeBuilder datablobtype = pmodule.DefineType ("$ArrayType$"+InitializedDataCount.ToString(),
692                                 TypeAttributes.Public|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed,
693                                 pmodule.assemblyb.corlib_value_type, PackingSize.Size1, data.Length);
694                         datablobtype.packing_size = PackingSize.Size1;
695                         datablobtype.class_size = data.Length;
696                         datablobtype.CreateType ();
697                         FieldBuilder res = DefineField (name, datablobtype, attributes|FieldAttributes.Assembly|FieldAttributes.Static|FieldAttributes.HasFieldRVA);
698                         res.SetRVAData (data);
699                         InitializedDataCount++;
700                         return res;
701                 }
702
703                 [MonoTODO]
704                 public FieldBuilder DefineUninitializedData( string name, int size, FieldAttributes attributes) {
705                         throw new NotImplementedException ();
706                 }
707
708                 public TypeToken TypeToken {
709                         get {
710                                 return new TypeToken (0x02000000 | table_idx);
711                         }
712                 }
713                 public void SetParent (Type parentType) {
714                         parent = parentType;
715                 }
716                 internal int get_next_table_index (object obj, int table, bool inc) {
717                         return pmodule.get_next_table_index (obj, table, inc);
718                 }
719
720         }
721 }