Exemple #1
0
        internal FieldBuilder(TypeBuilder type, string name, Type fieldType, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attribs)
        {
            this.typeBuilder = type;
            this.name        = name;
            this.pseudoToken = type.ModuleBuilder.AllocPseudoToken();
            this.nameIndex   = type.ModuleBuilder.Strings.Add(name);
            this.fieldSig    = FieldSignature.Create(fieldType, optionalCustomModifiers, requiredCustomModifiers);
            ByteBuffer sig = new ByteBuffer(5);

            fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig);
            this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig);
            this.attribs   = attribs;
            this.typeBuilder.ModuleBuilder.Field.AddVirtualRecord();
        }
Exemple #2
0
        public MutableFieldInfo CreateField(MutableType declaringType, string name, Type type, FieldAttributes attributes)
        {
            ArgumentUtility.CheckNotNull("declaringType", declaringType);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("type", type);

            if (type == typeof(void))
            {
                throw new ArgumentException("Field cannot be of type void.", "type");
            }

            MemberAttributesUtility.ValidateAttributes("fields", MemberAttributesUtility.InvalidFieldAttributes, attributes, "attributes");

            var signature = new FieldSignature(type);

            if (declaringType.AddedFields.Any(f => f.Name == name && FieldSignature.Create(f).Equals(signature)))
            {
                throw new InvalidOperationException("Field with equal name and signature already exists.");
            }

            return(new MutableFieldInfo(declaringType, name, type, attributes));
        }