示例#1
0
            public FieldSpec DefineInitializedData(byte[] data, Location loc)
            {
                Struct size_type;

                if (!size_types.TryGetValue(data.Length, out size_type))
                {
                    //
                    // Build common type for this data length. We cannot use
                    // DefineInitializedData because it creates public type,
                    // and its name is not unique among modules
                    //
                    size_type = new Struct(this, new MemberName("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
                    size_type.CreateContainer();
                    size_type.DefineContainer();

                    size_types.Add(data.Length, size_type);

                    // It has to work even if StructLayoutAttribute does not exist
                    size_type.TypeBuilder.__SetLayout(1, data.Length);
                }

                var name = "$field-" + fields.ToString("X");

                ++fields;
                const Modifiers fmod     = Modifiers.STATIC | Modifiers.INTERNAL;
                var             fbuilder = TypeBuilder.DefineField(name, size_type.CurrentType.GetMetaInfo(), ModifiersExtensions.FieldAttr(fmod) | FieldAttributes.HasFieldRVA);

                fbuilder.__SetDataAndRVA(data);

                return(new FieldSpec(CurrentType, null, size_type.CurrentType, fbuilder, fmod));
            }