public override string ToJson()
        {
            if (!base.IsIncluded && base.IsOptional)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            foreach (UIElement uc in Controls)
            {
                if (!(uc is DMControl))
                {
                    continue;
                }

                DMControl dmControl   = (DMControl)uc;
                string    controlJson = dmControl.ToJson();

                if (!String.IsNullOrEmpty(controlJson))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(",\n");
                    }
                    sb.Append(controlJson);
                }
            }

            StringBuilder asb = new StringBuilder();

            if (PropertyName.Length > 0)
            {
                asb.Append("\"" + PropertyName + "\" : ");
                asb.Append("{\n");
                asb.Append(sb.ToString());
                asb.Append("}\n");
            }
            else
            {
                asb.Append(sb.ToString());
            }

            return(asb.ToString());
        }
Exemplo n.º 2
0
        public virtual string ToJsonString()
        {
            bool useShortForm = true;

            StringBuilder json = new StringBuilder();

            json.Append("\"" + SectionName + "\" : ");

            if (ApplyProperties)
            {
                StringBuilder propertiesString = new StringBuilder();
                foreach (UIElement uc in PropertiesCollection)
                {
                    if (!(uc is DMControl))
                    {
                        continue;
                    }

                    DMControl dmControl   = (DMControl)uc;
                    string    controlJson = dmControl.ToJson();

                    if (!String.IsNullOrEmpty(controlJson))
                    {
                        if (propertiesString.Length > 0)
                        {
                            propertiesString.Append(",\n");
                        }
                        propertiesString.Append(controlJson);
                    }
                }

                if (propertiesString.Length > 0)
                {
                    json.Append("{\n");
                    json.Append("    \"" + DMJSonConstants.ApplyPropertiesString + "\" : ");
                    json.Append("{\n" + propertiesString.ToString() + "\n},");
                    json.Append("    \"" + DMJSonConstants.ReportPropertiesString + "\" : ");
                    if (ReportProperties)
                    {
                        json.Append("\"" + DMJSonConstants.YesString + "\"\n");
                    }
                    else
                    {
                        json.Append("\"" + DMJSonConstants.NoString + "\"\n");
                    }
                    json.Append("}");
                    useShortForm = false;
                }
            }

            if (useShortForm)
            {
                // This means applyProperties is either "no" or empty.
                if (ReportProperties)
                {
                    json.Append("\"" + DMJSonConstants.NoApplyYesReportString + "\"");
                }
                else
                {
                    json.Append("\"" + DMJSonConstants.NoApplyNoReportString + "\"");
                }
            }

            return(json.ToString());
        }