private static IReadOnlyList <FormSection> RetrieveFormSections(Type formType) { var properties = formType.GetProperties().Where(p => Attribute.IsDefined(p, typeof(DataTypeAttribute))).ToList(); var sections = properties.GroupBy(p => p.GetCustomAttribute <Forms.SectionAttribute>()?.Name).ToList(); var formSections = sections?.Select(section => { var formSection = new FormSection(section?.Key ?? string.Empty, section?.Select(p => { var formProperty = new FormProperty(p); var triggerAttribute = p.GetCustomAttributes().OfType <Forms.IAmConditionalTriggerAware>()?.FirstOrDefault(); if (triggerAttribute?.ConditionalTrigger != null) { formProperty.SetConditionalTrigger(triggerAttribute.ConditionalTrigger); } var triggerTargetAttribute = p.GetCustomAttribute <Forms.ConditionalTargetAttribute>(); if (triggerTargetAttribute != null) { formProperty.SetConditionalTriggerTarget(triggerTargetAttribute.TriggerKey); } return(formProperty); }) ?? Enumerable.Empty <FormProperty>()); return(formSection); }); return(formSections.ToList() ?? Enumerable.Empty <FormSection>().ToList()); }
public static IHtmlContent FormProperty(this IHtmlHelper htmlHelper, FormProperty formProperty) { if (htmlHelper.ViewData.IsDisplayMode()) { return(htmlHelper.Display(formProperty.Property.Name, formProperty.DataType)); } return(htmlHelper.Editor(formProperty.Property.Name, formProperty.DataType)); }