コード例 #1
0
        public static string WriteINI(IDictionary <string, IDictionary <string, string> > sections, RenderOptions options = null)
        {
            options = options ?? RenderOptions.Default;

            var sb = new StringBuilder();

            WriteINI(sections, sb, options);

            return(sb.ToString());
        }
コード例 #2
0
        public static void WriteSection(string name, IDictionary <string, string> childs, StringBuilder sb, RenderOptions options = null)
        {
            options = options ?? RenderOptions.Default;

            if (name == null)
            {
                return;
            }

            sb.Append("[");
            sb.Append(name.Replace("]", ""));
            sb.Append("]");
            sb.Append(options.lineBreak);

            foreach (var entry in childs)
            {
                WriteKeyValue(entry.Key, entry.Value, sb, options);
            }
        }
コード例 #3
0
        public static void WriteKeyValue(string name, string value, StringBuilder sb, RenderOptions options = null)
        {
            options = options ?? RenderOptions.Default;

            if (name == null)
            {
                return;
            }

            sb.Append(name.Replace("=", ""));

            if (options.spaceAfterKey)
            {
                sb.Append(options.space);
            }
            sb.Append("=");
            if (options.spaceBeforeValue)
            {
                sb.Append(options.space);
            }

            if (value != null)
            {
                sb.Append(value);
            }

            sb.Append(options.lineBreak);
        }
コード例 #4
0
        public static void WriteINI(IDictionary <string, IDictionary <string, string> > sections, StringBuilder sb, RenderOptions options = null)
        {
            bool firstSectionWritten = false;

            if (options.initialSectionName != null && sections.ContainsKey(options.initialSectionName) && sections[options.initialSectionName] != null)
            {
                foreach (var entry in sections[options.initialSectionName])
                {
                    WriteKeyValue(entry.Key, entry.Value, sb, options);
                }

                firstSectionWritten = true;
            }


            foreach (var entry in sections)
            {
                if (entry.Value == null)
                {
                    continue;
                }

                if (firstSectionWritten)
                {
                    WriteInterSectionLineBreaks(sb, options);
                }

                WriteSection(entry.Key, entry.Value, sb, options);
                firstSectionWritten = true;
            }
        }