Beispiel #1
0
        public void BuildField(ILConversion conversion, ConvertedTypeDefinition_I input, FieldDefinition field)
        {
            if (!(input is ConvertedTypeDefinitionWithFields_I typeWithFields))
            {
                throw new Exception("Trying to build a field on a type that does not support fields.");
            }

            var fieldAttributes = GetFieldAttributes(field);

            var boundFieldType = Execution.Types.Ensuring.EnsureToType(conversion, field.FieldType, out BoundTypeDefinitionMask_I semanticFieldType);

            var builder = typeWithFields.TypeBuilder.DefineField(field.Name, boundFieldType, fieldAttributes);

            if (field.HasConstant)
            {
                builder.SetConstant(field.Constant);
            }

            var convertedField = new ConvertedField()
            {
                FieldType       = semanticFieldType,
                Conversion      = conversion,
                FieldDefinition = field,
                FieldBuilder    = builder,
                UnderlyingField = builder,
                Name            = field.Name,
            };

            typeWithFields.Fields.ByName.Add(convertedField.Name, convertedField);

            CustomAttributes.BuildCustomAttributes(conversion, input, convertedField);
        }
Beispiel #2
0
        private static FormDefinition BuildConverted(Type type, Func <string, CultureInfo, object> deserializer)
        {
            var field = new ConvertedField(null, type, deserializer)
            {
                IsDirectBinding = true
            };

            return(BuildWith(field));
        }
        public void BuildCustomAttributes(ILConversion conversion, ConvertedTypeDefinition_I input, ConvertedField convertedField)
        {
            var builders = CreateCustomAttributeList(conversion, convertedField.FieldDefinition.CustomAttributes);

            for (int i = 0; i < builders.Count; i++)
            {
                var builder1 = builders[i];

                convertedField.FieldBuilder.SetCustomAttribute(builder1);
            }
        }