+ return DefineType (name, attr, parent, null, packsize, typesize);
+ }
+
+ public MethodInfo GetArrayMethod( Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
+ return new MonoArrayMethod (arrayClass, methodName, callingConvention, returnType, parameterTypes);
+ }
+
+ public EnumBuilder DefineEnum( string name, TypeAttributes visibility, Type underlyingType) {
+ EnumBuilder eb = new EnumBuilder (this, name, visibility, underlyingType);
+ return eb;
+ }
+
+ public override Type GetType( string className) {
+ return GetType (className, false, false);
+ }
+
+ public override Type GetType( string className, bool ignoreCase) {
+ return GetType (className, false, ignoreCase);
+ }
+
+ private TypeBuilder search_in_array (TypeBuilder[] arr, int validElementsInArray, string className) {
+ int i;
+ for (i = 0; i < validElementsInArray; ++i) {
+ if (String.Compare (className, arr [i].FullName, true, CultureInfo.InvariantCulture) == 0) {
+ return arr [i];
+ }
+ }
+ return null;
+ }
+
+ private TypeBuilder search_nested_in_array (TypeBuilder[] arr, int validElementsInArray, string className) {
+ int i;
+ for (i = 0; i < validElementsInArray; ++i) {
+ if (String.Compare (className, arr [i].Name, true, CultureInfo.InvariantCulture) == 0)
+ return arr [i];
+ }
+ return null;
+ }
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ private static extern Type create_modified_type (TypeBuilder tb, string modifiers);
+
+ static readonly char [] type_modifiers = {'&', '[', '*'};
+
+ private TypeBuilder GetMaybeNested (TypeBuilder t, string className) {
+ int subt;
+ string pname, rname;
+
+ subt = className.IndexOf ('+');
+ if (subt < 0) {
+ if (t.subtypes != null)
+ return search_nested_in_array (t.subtypes, t.subtypes.Length, className);
+ return null;
+ }
+ if (t.subtypes != null) {
+ pname = className.Substring (0, subt);
+ rname = className.Substring (subt + 1);
+ TypeBuilder result = search_nested_in_array (t.subtypes, t.subtypes.Length, pname);
+ if (result != null)
+ return GetMaybeNested (result, rname);
+ }
+ return null;
+ }
+
+ public override Type GetType (string className, bool throwOnError, bool ignoreCase) {
+ int subt;
+ string orig = className;
+ string modifiers;
+ TypeBuilder result = null;
+
+ if (types == null && throwOnError)
+ throw new TypeLoadException (className);
+
+ subt = className.IndexOfAny (type_modifiers);
+ if (subt >= 0) {
+ modifiers = className.Substring (subt);
+ className = className.Substring (0, subt);
+ } else
+ modifiers = null;
+
+ if (!ignoreCase) {
+ result = name_cache [className] as TypeBuilder;
+ } else {
+ subt = className.IndexOf ('+');
+ if (subt < 0) {
+ if (types != null)
+ result = search_in_array (types, num_types, className);
+ } else {
+ string pname, rname;
+ pname = className.Substring (0, subt);
+ rname = className.Substring (subt + 1);
+ result = search_in_array (types, num_types, pname);
+ if (result != null)
+ result = GetMaybeNested (result, rname);
+ }
+ }
+ if ((result == null) && throwOnError)
+ throw new TypeLoadException (orig);
+ if (result != null && (modifiers != null))
+ return create_modified_type (result, modifiers);
+ return result;
+ }
+
+ internal int get_next_table_index (object obj, int table, bool inc) {
+ if (table_indexes == null) {
+ table_indexes = new int [64];
+ for (int i=0; i < 64; ++i)
+ table_indexes [i] = 1;
+ /* allow room for .<Module> in TypeDef table */
+ table_indexes [0x02] = 2;
+ }
+ // Console.WriteLine ("getindex for table "+table.ToString()+" got "+table_indexes [table].ToString());
+ if (inc)
+ return table_indexes [table]++;
+ return table_indexes [table];
+ }
+
+ public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
+ if (cattrs != null) {
+ CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
+ cattrs.CopyTo (new_array, 0);
+ new_array [cattrs.Length] = customBuilder;
+ cattrs = new_array;
+ } else {
+ cattrs = new CustomAttributeBuilder [1];
+ cattrs [0] = customBuilder;
+ }
+ }
+ public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
+ SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
+ }
+
+ public ISymbolWriter GetSymWriter () {
+ return null;
+ }
+
+ public ISymbolDocumentWriter DefineDocument (string url, Guid language, Guid languageVendor, Guid documentType) {
+ return null;
+ }
+
+ public override Type [] GetTypes ()
+ {
+ if (types == null)
+ return new TypeBuilder [0];
+
+ int n = num_types;
+ TypeBuilder [] copy = new TypeBuilder [n];
+ Array.Copy (types, copy, n);
+
+ return copy;
+ }
+
+ public IResourceWriter DefineResource (string name, string description, ResourceAttributes attribute)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ if (name == String.Empty)
+ throw new ArgumentException ("name cannot be empty");
+ if (transient)
+ throw new InvalidOperationException ("The module is transient");
+ if (!assemblyb.IsSave)
+ throw new InvalidOperationException ("The assembly is transient");
+ ResourceWriter writer = new ResourceWriter (new MemoryStream ());
+ if (resource_writers == null)
+ resource_writers = new ArrayList ();
+ resource_writers.Add (writer);
+
+ // The data is filled out later
+ if (resources != null) {
+ MonoResource[] new_r = new MonoResource [resources.Length + 1];
+ System.Array.Copy(resources, new_r, resources.Length);
+ resources = new_r;
+ } else {
+ resources = new MonoResource [1];
+ }
+ int p = resources.Length - 1;
+ resources [p].name = name;
+ resources [p].attrs = attribute;
+
+ return writer;
+ }
+
+ public IResourceWriter DefineResource (string name, string description)
+ {
+ return DefineResource (name, description, ResourceAttributes.Public);
+ }
+
+ [MonoTODO]
+ public void DefineUnmanagedResource (byte[] resource)
+ {
+ if (resource == null)
+ throw new ArgumentNullException ("resource");
+
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void DefineUnmanagedResource (string resourceFileName)
+ {
+ if (resourceFileName == null)
+ throw new ArgumentNullException ("resourceFileName");
+ if (resourceFileName == String.Empty)
+ throw new ArgumentException ("resourceFileName");
+ if (!File.Exists (resourceFileName) || Directory.Exists (resourceFileName))
+ throw new FileNotFoundException ("File '" + resourceFileName + "' does not exists or is a directory.");
+
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void SetSymCustomAttribute (string name, byte[] data)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void SetUserEntryPoint (MethodInfo entryPoint)
+ {
+ if (entryPoint == null)
+ throw new ArgumentNullException ("entryPoint");
+ if (entryPoint.DeclaringType.Module != this)
+ throw new InvalidOperationException ("entryPoint is not contained in this module");
+ throw new NotImplementedException ();
+ }
+
+ public MethodToken GetMethodToken (MethodInfo method)
+ {
+ if (method == null)
+ throw new ArgumentNullException ("method");
+ if (method.DeclaringType.Module != this)
+ throw new InvalidOperationException ("The method is not in this module");
+ return new MethodToken (GetToken (method));
+ }
+
+ public MethodToken GetArrayMethodToken (Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
+ {
+ return GetMethodToken (GetArrayMethod (arrayClass, methodName, callingConvention, returnType, parameterTypes));
+ }
+
+
+ public MethodToken GetConstructorToken (ConstructorInfo con)
+ {
+ if (con == null)
+ throw new ArgumentNullException ("con");
+ return new MethodToken (GetToken (con));
+ }
+
+ public FieldToken GetFieldToken (FieldInfo field)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ if (field.DeclaringType.Module != this)
+ throw new InvalidOperationException ("The method is not in this module");
+ return new FieldToken (GetToken (field));
+ }
+
+ [MonoTODO]
+ public SignatureToken GetSignatureToken (byte[] sigBytes, int sigLength)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public SignatureToken GetSignatureToken (SignatureHelper sigHelper)
+ {
+ if (sigHelper == null)
+ throw new ArgumentNullException ("sigHelper");
+ return new SignatureToken (GetToken (sigHelper));
+ }
+
+ public StringToken GetStringConstant (string str)
+ {
+ if (str == null)
+ throw new ArgumentNullException ("str");
+ return new StringToken (GetToken (str));