コード例 #1
0
        internal static VxFormDefinition CreateFromModel(object model, VxFormLayoutOptions options)
        {
            // TODO: EXPANDO SWITCH
            var allProperties = VxHelpers.GetModelProperties(model.GetType());

            var rootFormDefinition = model.GetType().GetCustomAttribute <VxFormDefinition>();

            if (rootFormDefinition == null)
            {
                rootFormDefinition = VxFormDefinition.Create();
            }

            var defaultGroup = VxFormGroup.Create();


            foreach (var prop in allProperties)
            {
                if (VxFormGroup.IsFormGroup(prop))
                {
                    var nestedModel = prop.GetValue(model);
                    var formGroup   = VxFormGroup.CreateFromModel(nestedModel, options);
                    formGroup.Label = VxFormGroup.GetFormGroup(prop).Label;

                    rootFormDefinition.Groups.Add(formGroup);
                }
                else
                {
                    VxFormGroup.Add(prop.Name, defaultGroup, model, options);
                }
            }
            rootFormDefinition.Groups.Add(defaultGroup);

            return(rootFormDefinition);
        }
コード例 #2
0
        internal static VxFormGroup CreateFromModel(object modelInstance, VxFormLayoutOptions options)
        {
            var typeToCheck = modelInstance.GetType();

            // check for generics
            if (typeToCheck.IsGenericType)
            {
                typeToCheck = typeToCheck.GetGenericTypeDefinition();
            }

            var allProperties = VxHelpers.GetModelProperties(typeToCheck);

            var rootGroup = VxFormGroup.Create();

            foreach (var prop in allProperties)
            {
                VxFormGroup.Add(prop.Name, rootGroup, modelInstance, options);
            }

            return(rootGroup);
        }
コード例 #3
0
        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));
            }
        }