Beispiel #1
0
        /// <summary>
        /// Ands a field to the <see cref="Form"/>'s configuration.
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="property"></param>
        /// <param name="options"></param>
        /// <param name="attributeOverrides"></param>
        /// <returns></returns>
        public FormBuilder <T> AddOptions <TProperty>(Expression <Func <T, TProperty> > property,
                                                      IEnumerable <FormFieldOption> options,
                                                      FormFieldAttributeOverrides attributeOverrides = null)
        {
            MemberExpression            me    = property.Body as MemberExpression;
            FormField                   field = new() { Name = me.Member.Name, Type = FormFieldType.Array };
            Option <FormFieldAttribute> optionalFormFieldAttribute = me.Member.GetCustomAttribute <FormFieldAttribute>()
                                                                     .SomeNotNull();

            field.Options = options;

            UpdateAttributesField(property, field, optionalFormFieldAttribute, attributeOverrides.SomeNotNull());

            _fields.Add(field);

            return(this);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a field to the <see cref="Form"/>'s configuration.
        /// </summary>
        /// <remarks>
        ///
        /// </remarks>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="property"></param>
        /// <param name="attributes">Overrides field's attributes</param>
        /// <returns>The current instance.</returns>
        public FormBuilder <T> AddField <TProperty>(Expression <Func <T, TProperty> > property, FormFieldAttributeOverrides attributes = null)
        {
            if (property.Body is MemberExpression me)
            {
                FormField field = new FormField {
                    Name = me.Member.Name
                };
                Option <FormFieldAttribute> optionalFormFieldAttribute = me.Member.GetCustomAttribute <FormFieldAttribute>()
                                                                         .SomeNotNull();
                UpdateAttributesField(property, field, optionalFormFieldAttribute, attributes.SomeNotNull());

                field.Label   = field.Name;
                field.Enabled = attributes?.Enabled;

                _fields.Add(field);
            }

            return(this);
        }
Beispiel #3
0
 /// <summary>
 /// Adds a field to the <see cref="Form"/>'s configuration.
 /// </summary>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="property">Defines the property for which options will be added</param>
 /// <param name="options"></param>
 /// <param name="attributeOverrides"></param>
 /// <returns></returns>
 public FormBuilder <T> AddOptions <TProperty>(Expression <Func <T, TProperty> > property,
                                               IEnumerable <string> options,
                                               FormFieldAttributeOverrides attributeOverrides = null)
 => AddOptions(property, options.Select(opt => new FormFieldOption(opt, opt)), attributeOverrides);