Beispiel #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);
        }
Beispiel #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);
        }