public static Field[] ToFieldArray(this IEnumerable <ICustomFieldDefinition> items,
                                           ICollection <Field> collection, string namePrefix, Action <Field, ICustomFieldDefinition> initialize = null)
        {
            var result = new List <Field>();

            foreach (var item in items)
            {
                var   flags   = item.IsRequired ? Required : NotRequired;
                var   caption = ToLocalText(item.Title);
                var   name    = (namePrefix ?? "") + item.Name;
                Field field;

                switch (item.FieldType)
                {
                case CustomFieldType.Boolean:
                    field = new BooleanField(collection, name, caption, 0, flags);
                    break;

                case CustomFieldType.Date:
                    field = new DateTimeField(collection, name, caption, 0, flags)
                    {
                        DateTimeKind = DateTimeKind.Unspecified
                    };
                    break;

                case CustomFieldType.DateTime:
                    field = new DateTimeField(collection, name, caption, 0, flags)
                    {
                        DateTimeKind = DateTimeKind.Local
                    };
                    break;

                case CustomFieldType.Decimal:
                    field = new DecimalField(collection, name, caption, item.Size, flags);
                    break;

                case CustomFieldType.Int32:
                    field = new Int32Field(collection, name, caption, item.Size, flags);
                    break;

                case CustomFieldType.Int64:
                    field = new Int64Field(collection, name, caption, item.Size, flags);
                    break;

                default:
                    field = new StringField(collection, name, caption, item.Size, flags);
                    break;
                }

                field.DefaultValue = item.DefaultValue.TrimToNull();
                result.Add(field);

                if (initialize != null)
                {
                    initialize(field, item);
                }
            }

            return(result.ToArray());
        }
Ejemplo n.º 2
0
        public override void ValueFromJson(JsonReader reader, Row row, JsonSerializer serializer)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                _setValue(row, null);
                break;

            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Boolean:
                var v = Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture);
                if (EnumType == null)
                {
                    _setValue(row, v);
                }
                else
                {
                    _setValue(row, Int32Field.ConvertEnumFromInt(EnumType, v));
                }
                break;

            case JsonToken.String:
                string s = ((string)reader.Value).TrimToNull();
                if (s == null)
                {
                    _setValue(row, null);
                }
                else if (EnumType == null)
                {
                    _setValue(row, Convert.ToInt64(s, CultureInfo.InvariantCulture));
                }
                else
                {
                    _setValue(row, Int32Field.ConvertEnumFromString(EnumType, s));
                }
                break;

            default:
                throw JsonUnexpectedToken(reader);
            }

            if (row.tracking)
            {
                row.FieldAssignedValue(this);
            }
        }
Ejemplo n.º 3
0
            public RowFields()
                : base(R.TableName, "")
            {
                DataEnumId = new Int32Field(this, "DataEnumId", "ID", 0, FieldFlags.Identity,
                                            r => ((R)r)._DataEnumId, (r, v) => ((R)r)._DataEnumId = v);

                EnumType = new StringField(this, "EnumType", "Enum Tipi", 30, FieldFlags.Required,
                                           r => ((R)r)._EnumType, (r, v) => ((R)r)._EnumType = v);

                ValueId = new Int32Field(this, "ValueId", "Değer No", 0, FieldFlags.Required,
                                         r => ((R)r)._ValueId, (r, v) => ((R)r)._ValueId = v);

                ValueKey = new StringField(this, "ValueKey", "Değer Kodu", 30, FieldFlags.Required,
                                           r => ((R)r)._ValueKey, (r, v) => ((R)r)._ValueKey = v);

                DisplayOrder = new Int32Field(this, "DisplayOrder", "Gösterim Sırası", 0, FieldFlags.Required,
                                              r => ((R)r)._DisplayOrder, (r, v) => ((R)r)._DisplayOrder = v);
            }
Ejemplo n.º 4
0
 public static ValueFormatter Enum(Int32Field field)
 {
     return(Enum(field.EnumType));
 }
Ejemplo n.º 5
0
 public static void SetEnumFormatter(IDictionary <string, ValueFormatter> formatters, Int32Field field)
 {
     formatters[field.Name] = Enum(field.EnumType);
 }