How to set up custom syntax and formatting rules just like in Xml documents

// Create a new instance of the IniWriterFormattingSettings
IniWriterFormattingSettings format = new IniWriterFormattingSettings() {
    IndentParameters = true,
    SpaceBeforeDelimiter = false,
    SpaceBeforeCommentStart = true
};

// Set some syntax rules
IniSyntaxDefinition syntax = new IniSyntaxDefinition() {
    NameValueDelimiter = ':',
    CommentStartChar = '#',
    QuoteChar = '\''
};

// Apply
myDocument.SyntaxDefinition = syntax;
myDocument.OutputFormatting = format;

Your Ini file will look like this:
[Section]
    Parameter1: value # some comment
    Parameter2: 'another value' # another comment

Default settings

SyntaxDefinition
  • CommentStartChar = ';'
  • NameValueDelimiter = '='
  • QuoteChar = '"'
  • RequireQuotes = false

IniWriterFormattingSettings
  • PlaceSectionCommentsBeforeHeader = false
  • SeparateSections = true
  • SpaceAfterCommentStart = true
  • SpaceAfterDelimiter = true
  • SpaceBeforeCommentStart = false
  • SpaceBeforeDelimiter = true

Last edited Mar 8, 2009 at 11:55 AM by BlueCode, version 2

Comments

No comments yet.