コード例 #1
0
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
        /// <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
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
        /// <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 プロジェクト: wangchengqun/azos
        /// <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
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
 /// <summary>
 /// Writes LaconicConfiguration data to the string
 /// </summary>
 public static string Write(Configuration data, LaconfigWritingOptions options = null)
 {
     return(Write(data.Root, options));
 }
コード例 #5
0
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
 /// <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));
 }
コード例 #6
0
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
 /// <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);
 }
コード例 #7
0
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
        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("=");

                var v = anode.VerbatimValue;

                if (v == null)
                {
                    sb.Append("null");
                }
                else
                {
                    writeString(sb, v);
                }
            }

            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('}');
            }
        }
コード例 #8
0
ファイル: LaconfigWriter.cs プロジェクト: wangchengqun/azos
 /// <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);
 }
コード例 #9
0
 /// <summary>
 /// Writes LaconicConfiguration data to the string
 /// </summary>
 public static string Write(Configuration data, LaconfigWritingOptions options = null)
 => Write(data.Root, options);