/// <summary> /// Get the values of built-in attributes like <see cref="DisplayAttribute"/> and patch it to a <see cref="VxFormLayoutAttribute"/> /// </summary> /// <param name="layoutAttr">The attribute to patch</param> /// <param name="prop">Property for reflection purpouses</param> private static void PatchLayoutWithBuiltInAttributes(VxFormElementLayoutAttribute layoutAttr, PropertyInfo prop) { var displayAttribute = prop .GetCustomAttributes(typeof(DisplayAttribute), false) .FirstOrDefault() as DisplayAttribute; if (displayAttribute != null) { layoutAttr.Label = displayAttribute.GetName(); layoutAttr.Order = displayAttribute.GetOrder().GetValueOrDefault(); } }
internal static VxFormRow Create(VxFormElementLayoutAttribute layoutAttr, VxFormRowLayoutAttribute vxFormRowLayoutAttribute, VxFormLayoutOptions options) { // If no rowid is specified use the name instead var output = layoutAttr.RowId == 0 ? new VxFormRow(layoutAttr.FieldIdentifier) : new VxFormRow(layoutAttr.RowId); output.RowLayoutAttribute = vxFormRowLayoutAttribute; if (options.LabelOrientation == LabelOrientation.LEFT && output.RowLayoutAttribute?.Label != null) { output.Label = vxFormRowLayoutAttribute.Label; } return(output); }
internal static void Add(string fieldIdentifier, VxFormGroup group, object modelInstance, VxFormLayoutOptions options) { // TODO: EXPANDO switch var prop = modelInstance.GetType().GetProperty(fieldIdentifier); var layoutAttr = prop.GetCustomAttribute <VxFormElementLayoutAttribute>(); var allRowLayoutAttributes = VxHelpers.GetAllAttributes <VxFormRowLayoutAttribute>(prop.DeclaringType); // If no attribute is found use the name of the property if (layoutAttr == null) { layoutAttr = new VxFormElementLayoutAttribute() { Label = GetLabel(fieldIdentifier, modelInstance) } } ; PatchLayoutWithBuiltInAttributes(layoutAttr, prop); // Check if row already exists var foundRow = group.Rows.Find(value => value.Id == layoutAttr.RowId.ToString()); if (foundRow == null) { foundRow = VxFormRow.Create(layoutAttr, allRowLayoutAttributes.Find(x => x.Id == layoutAttr.RowId), options); group.Rows.Add(foundRow);; } var formColumn = VxFormElementDefinition.Create(fieldIdentifier, layoutAttr, modelInstance, options); VxFormRow.AddColumn(foundRow, formColumn, options); // WHen there is a VxFormRowLayout found use the name if specified, this also sets the row to combined labels if (options.LabelOrientation == LabelOrientation.LEFT && foundRow.RowLayoutAttribute?.Label == null) { foundRow.Label = string.Join(", ", foundRow.Columns.ConvertAll(x => x.RenderOptions.Label)); } }
internal static VxFormElementDefinition Create(string fieldname, VxFormElementLayoutAttribute layoutAttr, object modelInstance, VxFormLayoutOptions options) { return(new VxFormElementDefinition(fieldname, layoutAttr, modelInstance)); }
public VxFormElementDefinition(string fieldname, VxFormElementLayoutAttribute layoutAttr, object modelInstance) { RenderOptions = layoutAttr; Name = fieldname; Model = modelInstance; }