예제 #1
0
        /// <summary>
        /// Returns a padding string for specified level per set options
        /// </summary>
        public static string Indent(int level, LaconfigWritingOptions opt)
        {
            if (opt.IndentWidth > 0)
            {
                return(string.Empty.PadLeft(level * opt.IndentWidth));
            }

            return(string.Empty);
        }
예제 #2
0
        /// <summary>
        /// Appends LaconicConfiguration data into the instance of StringBuilder
        /// </summary>
        public static void Write(IConfigSectionNode data, StringBuilder sb, LaconfigWritingOptions options = null)
        {
            if (options == null)
            {
                options = LaconfigWritingOptions.PrettyPrint;
            }

            writeSection(sb, data, 0, options);
        }
예제 #3
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
        /// <summary>
        /// Writes LaconicConfiguration data to the string
        /// </summary>
        public static string Write(IConfigSectionNode data, LaconfigWritingOptions options = null)
        {
            if (options==null) options = LaconfigWritingOptions.PrettyPrint;

            var sb = new StringBuilder();

            writeSection(sb, data, 0, options);

            return sb.ToString();
        }
예제 #4
0
        /// <summary>
        /// Writes LaconicConfiguration data to the string
        /// </summary>
        public static string Write(IConfigSectionNode data, LaconfigWritingOptions options = null)
        {
            if (options == null)
            {
                options = LaconfigWritingOptions.PrettyPrint;
            }

            var sb = new StringBuilder();

            writeSection(sb, data, 0, options);

            return(sb.ToString());
        }
예제 #5
0
 /// <summary>
 /// Appends LaconicConfiguration data into the instance of StringBuilder
 /// </summary>
 public static void Write(Configuration data, StringBuilder sb, LaconfigWritingOptions options = null)
 {
     Write(data.Root, sb, options);
 }
예제 #6
0
 /// <summary>
 /// Writes LaconicConfiguration data to the string
 /// </summary>
 public static string Write(Configuration data, LaconfigWritingOptions options = null)
 {
     return(Write(data.Root, options));
 }
예제 #7
0
파일: Laconic.cs 프로젝트: yhhno/nfx
        public void Options_DontWriteRootSectionDeclaration()
        {
            var conf = "nfx=90{a=1 b=2 c{d=5}}".AsLaconicConfig(handling: ConvertErrorHandling.Throw);

              var opt = new LaconfigWritingOptions{ DontWriteRootSectionDeclaration = true };

              var saved = conf.Configuration.ToLaconicString(opt);
              Console.WriteLine(saved);

              Assert.AreEqual("a=1 b=2 c{d=5}", saved);

              opt = new LaconfigWritingOptions{ /* DontWriteRootSectionDeclaration = false - default */ };

              saved = conf.Configuration.ToLaconicString(opt).Trim();
              Console.WriteLine(saved);

              Assert.AreEqual("nfx=90{a=1 b=2 c{d=5}}", saved);
        }
예제 #8
0
 /// <summary>
 /// Saves configuration into a file
 /// </summary>
 public void SaveAs(string filename, LaconfigWritingOptions options = null)
 {
   using(var fs = new FileStream(filename, FileMode.Create))
      LaconfigWriter.Write(this, fs, options);
   base.SaveAs(filename);
 }
예제 #9
0
 /// <summary>
 /// Writes LaconicConfiguration data to the stream
 /// </summary>
 public static void Write(Configuration data, Stream stream, LaconfigWritingOptions options = null, Encoding encoding = null)
 {
     Write(data.Root, stream, options, encoding);
 }
예제 #10
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
 /// <summary>
 /// Writes LaconicConfiguration data to the stream
 /// </summary>
 public static void Write(IConfigSectionNode data, Stream stream, LaconfigWritingOptions options = null, Encoding encoding = null)
 {
     using(var writer = new StreamWriter(stream, encoding ?? UTF8Encoding.UTF8))
         writer.Write( Write(data, options) );
 }
예제 #11
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
 /// <summary>
 /// Writes LaconicConfiguration data to the stream
 /// </summary>
 public static void Write(Configuration data, Stream stream, LaconfigWritingOptions options = null, Encoding encoding = null)
 {
     Write(data.Root, stream, options, encoding);
 }
예제 #12
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
        /// <summary>
        /// Returns a padding string for specified level per set options
        /// </summary>
        public static string Indent(int level, LaconfigWritingOptions opt)
        {
            if (opt.IndentWidth>0) return string.Empty.PadLeft(level * opt.IndentWidth);

            return string.Empty;
        }
예제 #13
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
        private static void writeSection(StringBuilder sb, IConfigSectionNode section, int level, LaconfigWritingOptions opt)
        {
            var writeSectionDecl = section.Parent.Exists || !opt.DontWriteRootSectionDeclaration;

                            if (writeSectionDecl)
                            {
                              if (opt.SectionLineBreak && section.Parent.Exists)
                              {
                                sb.AppendLine();
                                sb.Append(Indent(level, opt));
                              }
                           //   else sb.Append(' ');

                              writeString(sb, section.Name);
                              var value = section.VerbatimValue;
                              if (value.IsNotNullOrWhiteSpace())
                              {
                                  sb.Append("=");
                                  writeString(sb, value);
                              }

                              if (opt.SectionLineBreak)
                              {
                                sb.AppendLine();
                                sb.Append(Indent(level, opt));
                              }
                              sb.Append('{');
                            }

                            bool wasAttr = false;
                            foreach(var anode in section.Attributes)
                            {
                                if (opt.AttributeLineBreak)
                                {
                                  sb.AppendLine();
                                  sb.Append(Indent(level+1, opt));
                                }
                                else if (wasAttr) sb.Append(' ');

                                wasAttr = true;
                                writeString(sb, anode.Name);
                                sb.Append("=");
                                writeString(sb, anode.VerbatimValue);
                            }

                            bool wasChild = false;
                            foreach(var csect in section.Children)
                            {
                                if (!wasChild && wasAttr && !opt.SectionLineBreak) sb.Append(' ');

                                wasChild = true;
                                writeSection(sb, csect, level+1, opt);
                            }

                            if (writeSectionDecl)
                            {
                              if (opt.SectionLineBreak)
                              {
                                sb.AppendLine();
                                sb.Append(Indent(level, opt));
                              }
                              sb.Append('}');
                            }
        }
예제 #14
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
        /// <summary>
        /// Appends LaconicConfiguration data into the instance of StringBuilder
        /// </summary>
        public static void Write(IConfigSectionNode data, StringBuilder sb, LaconfigWritingOptions options = null)
        {
            if (options==null) options = LaconfigWritingOptions.PrettyPrint;

            writeSection(sb, data, 0, options);
        }
예제 #15
0
        private static void writeSection(StringBuilder sb, IConfigSectionNode section, int level, LaconfigWritingOptions opt)
        {
            if (opt.SectionLineBreak)
            {
                sb.AppendLine();
                sb.Append(Indent(level, opt));
            }
            else
            {
                sb.Append(' ');
            }

            writeString(sb, section.Name);
            var value = section.VerbatimValue;

            if (value.IsNotNullOrWhiteSpace())
            {
                sb.Append("=");
                writeString(sb, value);
            }

            if (opt.SectionLineBreak)
            {
                sb.AppendLine();
                sb.Append(Indent(level, opt));
            }
            sb.Append('{');

            foreach (var anode in section.Attributes)
            {
                if (opt.AttributeLineBreak)
                {
                    sb.AppendLine();
                    sb.Append(Indent(level + 1, opt));
                }
                else
                {
                    sb.Append(' ');
                }

                writeString(sb, anode.Name);
                sb.Append("=");
                writeString(sb, anode.VerbatimValue);
            }
            sb.Append(' ');
            foreach (var csect in section.Children)
            {
                writeSection(sb, csect, level + 1, opt);
            }

            if (opt.SectionLineBreak)
            {
                sb.AppendLine();
                sb.Append(Indent(level, opt));
            }
            sb.Append('}');
        }
예제 #16
0
        private static void writeSection(StringBuilder sb, IConfigSectionNode section, int level, LaconfigWritingOptions opt)
        {
            var writeSectionDecl = section.Parent.Exists || !opt.DontWriteRootSectionDeclaration;

            if (writeSectionDecl)
            {
                if (opt.SectionLineBreak && section.Parent.Exists)
                {
                    sb.AppendLine();
                    sb.Append(Indent(level, opt));
                }
                //   else sb.Append(' ');

                writeString(sb, section.Name);
                var value = section.VerbatimValue;
                if (value.IsNotNullOrWhiteSpace())
                {
                    sb.Append("=");
                    writeString(sb, value);
                }

                if (opt.SectionLineBreak)
                {
                    sb.AppendLine();
                    sb.Append(Indent(level, opt));
                }
                sb.Append('{');
            }

            bool wasAttr = false;

            foreach (var anode in section.Attributes)
            {
                if (opt.AttributeLineBreak)
                {
                    sb.AppendLine();
                    sb.Append(Indent(level + 1, opt));
                }
                else if (wasAttr)
                {
                    sb.Append(' ');
                }

                wasAttr = true;
                writeString(sb, anode.Name);
                sb.Append("=");
                writeString(sb, anode.VerbatimValue);
            }

            bool wasChild = false;

            foreach (var csect in section.Children)
            {
                if (!wasChild && wasAttr && !opt.SectionLineBreak)
                {
                    sb.Append(' ');
                }

                wasChild = true;
                writeSection(sb, csect, level + 1, opt);
            }

            if (writeSectionDecl)
            {
                if (opt.SectionLineBreak)
                {
                    sb.AppendLine();
                    sb.Append(Indent(level, opt));
                }
                sb.Append('}');
            }
        }
예제 #17
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
 /// <summary>
 /// Writes LaconicConfiguration data to the string
 /// </summary>
 public static string Write(Configuration data, LaconfigWritingOptions options = null)
 {
     return Write(data.Root, options);
 }
예제 #18
0
 /// <summary>
 /// Writes LaconicConfiguration data to the stream
 /// </summary>
 public static void Write(IConfigSectionNode data, Stream stream, LaconfigWritingOptions options = null, Encoding encoding = null)
 {
     using (var writer = new StreamWriter(stream, encoding ?? UTF8Encoding.UTF8))
         writer.Write(Write(data, options));
 }
예제 #19
0
파일: LaconfigWriter.cs 프로젝트: yhhno/nfx
 /// <summary>
 /// Appends LaconicConfiguration data into the instance of StringBuilder
 /// </summary>
 public static void Write(Configuration data, StringBuilder sb, LaconfigWritingOptions options = null)
 {
     Write(data.Root, sb, options);
 }
예제 #20
0
 /// <summary>
 /// Saves laconic configuration into string in Laconfig format and returns it
 /// </summary>
 public string SaveToString(LaconfigWritingOptions options = null)
 {
   return LaconfigWriter.Write(this, options);
 }
예제 #21
0
                        private static void writeSection(StringBuilder sb, IConfigSectionNode section, int level, LaconfigWritingOptions opt)
                        {
                            if (opt.SectionLineBreak)
                            { 
                              sb.AppendLine();
                              sb.Append(Indent(level, opt));
                            }
                            else sb.Append(' ');
                           
                            writeString(sb, section.Name);   
                            var value = section.VerbatimValue;
                            if (value.IsNotNullOrWhiteSpace())
                            {
                                sb.Append("=");
                                writeString(sb, value);
                            }

                            if (opt.SectionLineBreak)
                            { 
                              sb.AppendLine();
                              sb.Append(Indent(level, opt));
                            }
                            sb.Append('{');

                            foreach(var anode in section.Attributes)
                            {
                                if (opt.AttributeLineBreak)
                                { 
                                  sb.AppendLine();
                                  sb.Append(Indent(level+1, opt));
                                }
                                else sb.Append(' ');

                                writeString(sb, anode.Name);   
                                sb.Append("=");
                                writeString(sb, anode.VerbatimValue);
                            }
                            sb.Append(' ');
                            foreach(var csect in section.Children)
                            {
                                writeSection(sb, csect, level+1, opt);
                            }

                            if (opt.SectionLineBreak)
                            { 
                              sb.AppendLine();
                              sb.Append(Indent(level, opt));
                            }
                            sb.Append('}');
                        }