示例#1
0
        /// <summary>
        /// Converts this FDSSection to a textual representation of itself.
        /// </summary>
        /// <param name="tabulation">How many tabs to start with. Generally do not set this.</param>
        /// <param name="newline">What string to use as a new line. Generally do not set this.</param>
        /// <returns>The string.</returns>
        public string SaveToString(int tabulation = 0, string newline = null)
        {
            if (newline == null)
            {
                newline = "\n";
            }
            StringBuilder sb = new StringBuilder();

            foreach (string key in Data.Keys)
            {
                FDSData dat = Data[key];
                foreach (string str in dat.PrecedingComments)
                {
                    sb.Append('\t', tabulation);
                    sb.Append("#").Append(str).Append(newline);
                }
                sb.Append('\t', tabulation);
                sb.Append(FDSUtility.EscapeKey(key));
                if (dat.Internal is FDSSection)
                {
                    sb.Append(":").Append(newline).Append(((FDSSection)dat.Internal).SaveToString(tabulation + 1, newline));
                }
                else if (dat.Internal is byte[])
                {
                    sb.Append("= ").Append(dat.Outputable()).Append(newline);
                }
                else if (dat.Internal is List <FDSData> datums)
                {
                    sb.Append(":").Append(newline);
                    foreach (FDSData cdat in datums)
                    {
                        foreach (string com in cdat.PrecedingComments)
                        {
                            sb.Append('\t', tabulation);
                            sb.Append("#").Append(com).Append(newline);
                        }
                        sb.Append('\t', tabulation);
                        sb.Append("- ").Append(FDSUtility.Escape(cdat.Outputable())).Append(newline);
                    }
                }
                else
                {
                    sb.Append(": ").Append(FDSUtility.Escape(dat.Outputable())).Append(newline);
                }
            }
            return(sb.ToString());
        }
示例#2
0
 /// <summary>
 /// Returns the output-able string representation of this data.
 /// </summary>
 /// <returns>The resultant data.</returns>
 public string Outputable()
 {
     if (Internal is List <FDSData> )
     {
         StringBuilder sb = new StringBuilder();
         foreach (FDSData dat in (List <FDSData>)Internal)
         {
             sb.Append(dat.Outputable()).Append('|');
         }
         return(sb.ToString());
     }
     if (Internal is byte[])
     {
         return(Convert.ToBase64String((byte[])Internal, Base64FormattingOptions.None));
     }
     if (Internal is bool)
     {
         return(((bool)Internal) ? "true" : "false");
     }
     return(FDSUtility.Escape(Internal.ToString()));
 }