Exemplo n.º 1
0
 /// <summary>Formats whole section.</summary>
 /// <param name="preserveIntendation">Determines whether intendation should be preserved.</param>
 public void Format(bool preserveIntendation)
 {
     for (int i = 0; i < elements.Count; i++)
     {
         IniFileElement el         = elements[i];
         string         lastIntend = el.Intendation;
         el.FormatDefault();
         if (preserveIntendation)
         {
             el.Intendation = lastIntend;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>Writes INI file element to the file.</summary>
        /// <param name="element">Element to write.</param>
        private static void WriteElement(StreamWriter writer, IniFileElement element)
        {
            if (!PreserveFormatting)
            {
                element.FormatDefault();
            }

            // do not write if:
            if (!( // 1) element is a blank line AND blank lines are not allowed
                    (element is IniFileBlankLine && !AllowBlankLines)
                    // 2) element is an empty value AND empty values are not allowed
                    || (!AllowEmptyValues && element is IniFileValue && ((IniFileValue)element).Value == "")))
            {
                writer.WriteLine(element.Line);
            }
        }
Exemplo n.º 3
0
        /// <summary>Formats whole INI file.</summary>
        /// <param name="preserveIntendation">If true, old intendation will be standarized but not removed.</param>
        public void Format(bool preserveIntendation)
        {
            string lastSectIntend = "";
            string lastValIntend  = "";

            for (int i = 0; i < elements.Count; i++)
            {
                IniFileElement el = elements[i];
                if (preserveIntendation)
                {
                    if (el is IniFileSectionStart)
                    {
                        lastValIntend = lastSectIntend = el.Intendation;
                    }
                    else if (el is IniFileValue)
                    {
                        lastValIntend = el.Intendation;
                    }
                }
                el.FormatDefault();
                if (preserveIntendation)
                {
                    if (el is IniFileSectionStart)
                    {
                        el.Intendation = lastSectIntend;
                    }
                    else if (el is IniFileCommentary && i != elements.Count - 1 && !(elements[i + 1] is IniFileBlankLine))
                    {
                        el.Intendation = elements[i + 1].Intendation;
                    }
                    else
                    {
                        el.Intendation = lastValIntend;
                    }
                }
            }
        }