コード例 #1
0
        protected virtual AngularFormGroup GetGroup(TypeScriptModel model)
        {
            AngularFormGroup group = new AngularFormGroup(model.Name);

            TypeScriptPropertyDefinition[] definitions = this.GetPropertyDefinitions(model);

            foreach (TypeScriptPropertyDefinition definition in definitions)
            {
                group.Controls.Add(GetControl(definition));
            }

            return(group);
        }
コード例 #2
0
        protected virtual string Print(AngularFormGroup group, int deep)
        {
            StringBuilder sb = new StringBuilder();

            string indents = "\t\t";

            for (int i = 0; i < deep; i++)
            {
                indents += "\t";
            }

            bool                   isLast;
            string                 validators;
            IAngularControl        control;
            AngularAbstractControl abstractControl;

            for (int i = 0; i < group.Controls.Count; i++)
            {
                isLast  = i + 1 == group.Controls.Count;
                control = group.Controls[i];

                if (control is AngularAbstractControl)
                {
                    abstractControl = control as AngularAbstractControl;
                    validators      = (abstractControl.Validators.Any()
                                                ? abstractControl.Validators.Count > 1
                                                        ? $", [{string.Join(", ", abstractControl.Validators.Select(o => o.Name))}]"
                                                        : $", {abstractControl.Validators[0].Name}"
                                                : string.Empty);
                    sb.AppendLine($"{indents}{control.Name}: new {abstractControl.Control}({abstractControl.Value}{validators}){(isLast ? string.Empty : ",")}");
                }
                else if (control is AngularFormGroup)
                {
                    sb.AppendLine($"{indents}{control.Name}: new FormGroup({{");
                    sb.Append(this.Print(control as AngularFormGroup, deep + 1));
                    sb.AppendLine($"{indents}}}){(isLast ? string.Empty : ",")}");
                }
            }

            return(sb.ToString());
        }