Beispiel #1
0
        private FieldBuilder DefineDataImpl(string name, int size, FieldAttributes attributes)
        {
            ArgumentException.ThrowIfNullOrEmpty(name);
            if (global_type_created != null)
            {
                throw new InvalidOperationException("global fields already created");
            }
            if ((size <= 0) || (size >= 0x3f0000))
            {
                throw new ArgumentException("Data size must be > 0 and < 0x3f0000", null as string);
            }

            CreateGlobalType();

            string typeName     = "$ArrayType$" + size;
            Type?  datablobtype = GetType(typeName, false, false);

            if (datablobtype == null)
            {
                TypeBuilder tb = DefineType(typeName,
                                            TypeAttributes.Public | TypeAttributes.ExplicitLayout | TypeAttributes.Sealed,
                                            typeof(ValueType), null, FieldBuilder.RVADataPackingSize(size), size);
                tb.CreateType();
                datablobtype = tb;
            }
            FieldBuilder fb = global_type !.DefineField(name, datablobtype, attributes | FieldAttributes.Static);

            if (global_fields != null)
            {
                FieldBuilder[] new_fields = new FieldBuilder[global_fields.Length + 1];
                Array.Copy(global_fields, new_fields, global_fields.Length);
                new_fields[global_fields.Length] = fb;
                global_fields = new_fields;
            }
            else
            {
                global_fields = new FieldBuilder[] { fb };
            }
            return(fb);
        }