protected virtual void WriteComments(List <string> comments,
                                      StringBuilder sb,
                                      IniScheme scheme,
                                      IniFormattingConfiguration format)
 {
     foreach (string comment in comments)
     {
         sb.Append($"{scheme.CommentString}{comment}{format.NewLineString}");
     }
 }
        protected virtual void WriteProperties(PropertyCollection properties,
                                               StringBuilder sb,
                                               IniScheme scheme,
                                               IniFormattingConfiguration format)
        {
            foreach (Property property in properties)
            {
                // Write comments
                WriteComments(property.Comments, sb, scheme, format);

                if (format.NewLineBeforeProperty)
                {
                    sb.Append(format.NewLineString);
                }

                //Write key and value
                sb.Append($"{property.Key}{format.SpacesBetweenKeyAndAssigment}{scheme.PropertyAssigmentString}{format.SpacesBetweenAssigmentAndValue}{property.Value}{format.NewLineString}");

                if (format.NewLineAfterProperty)
                {
                    sb.Append(format.NewLineString);
                }
            }
        }
        protected virtual void WriteSection(Section section,
                                            StringBuilder sb,
                                            IniScheme scheme,
                                            IniFormattingConfiguration format)
        {
            // Comments
            WriteComments(section.Comments, sb, scheme, format);

            // Write blank line before section, but not if it is the first line
            if (format.NewLineBeforeSection && sb.Length > 0)
            {
                sb.Append(format.NewLineString);
            }

            // Write section name
            sb.Append($"{scheme.SectionStartString}{section.Name}{scheme.SectionEndString}{format.NewLineString}");

            if (format.NewLineAfterSection)
            {
                sb.Append(format.NewLineString);
            }

            WriteProperties(section.Properties, sb, scheme, format);
        }
Example #4
0
 /// <summary>
 ///     Initialzes an IniData instance with a given scheme
 /// </summary>
 /// <param name="scheme"></param>
 public IniData(IniScheme scheme)
     : this()
 {
     _scheme = scheme.DeepClone();
 }
Example #5
0
 /// <summary>
 ///     Initializes an empty IniData instance.
 /// </summary>
 public IniData()
 {
     Global   = new PropertyCollection();
     Sections = new SectionCollection();
     _scheme  = new IniScheme();
 }
Example #6
0
 public IniDataCaseInsensitive(IniScheme scheme)
 {
     Sections = new SectionCollection(StringComparer.OrdinalIgnoreCase);
     Global   = new PropertyCollection(StringComparer.OrdinalIgnoreCase);
     _scheme  = scheme.DeepClone();
 }
Example #7
0
 /// <summary>
 ///     Ctor
 /// </summary>
 public IniDataParser()
 {
     Scheme           = new IniScheme();
     Configuration    = new IniParserConfiguration();
     _errorExceptions = new List <Exception>();
 }