예제 #1
0
        /// <summary>
        /// Loads the file not saving comments.
        /// </summary>
        private void LoadReader(IniReader reader)
        {
            reader.IgnoreComments = false;
            bool       sectionFound = false;
            IniSection section      = null;

            try {
                while (reader.Read())
                {
                    switch (reader.Type)
                    {
                    case IniType.Empty:
                        if (!sectionFound)
                        {
                            initialComment.Add(reader.Comment);
                        }
                        else
                        {
                            section.Set(reader.Comment);
                        }

                        break;

                    case IniType.Section:
                        sectionFound = true;
                        // If section already exists then overwrite it
                        if (sections[reader.Name] != null)
                        {
                            sections.Remove(reader.Name);
                        }
                        section = new IniSection(reader.Name, reader.Comment);
                        sections.Add(section);

                        break;

                    case IniType.Key:
                        if (section.GetValue(reader.Name) == null)
                        {
                            section.Set(reader.Name, reader.Value, reader.Comment);
                        }
                        break;
                    }
                }
            } catch (Exception ex) {
                throw ex;
            } finally {
                // Always close the file
                reader.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a proper INI reader depending upon the type parameter.
        /// </summary>
        private IniReader GetIniReader(TextReader reader, IniFileType type)
        {
            IniReader result = new IniReader(reader);

            switch (type)
            {
            case IniFileType.Standard:
                // do nothing
                break;

            case IniFileType.PythonStyle:
                result.AcceptCommentAfterKey = false;
                result.SetCommentDelimiters(new char[] { ';', '#' });
                result.SetAssignDelimiters(new char[] { ':' });
                break;

            case IniFileType.SambaStyle:
                result.AcceptCommentAfterKey = false;
                result.SetCommentDelimiters(new char[] { ';', '#' });
                result.LineContinuation = true;
                break;

            case IniFileType.MysqlStyle:
                result.AcceptCommentAfterKey      = false;
                result.AcceptNoAssignmentOperator = true;
                result.SetCommentDelimiters(new char[] { '#' });
                result.SetAssignDelimiters(new char[] { ':', '=' });
                break;

            case IniFileType.WindowsStyle:
                result.ConsumeAllKeyText = true;
                break;
            }

            return(result);
        }
예제 #3
0
 /// <include file='IniException.xml' path='//Constructor[@name="ConstructorTextReader"]/docs/*' />
 internal IniException(IniReader reader, string message)
     : this(message)
 {
     iniReader    = reader;
     this.message = message;
 }
예제 #4
0
 /// <include file='IniDocument.xml' path='//Constructor[@name="ConstructorIniReader"]/docs/*' />
 public IniDocument(IniReader reader)
 {
     fileType = IniFileType.Standard;
     Load(reader);
 }
예제 #5
0
 /// <include file='IniDocument.xml' path='//Method[@name="LoadIniReader"]/docs/*' />
 public void Load(IniReader reader)
 {
     LoadReader(reader);
 }