Exemple #1
0
        private void setComment(IniFileElement el, string comment)
        {
            int index = parent.elements.IndexOf(el);

            if (IniFileEx.CommentChars.Length == 0)
            {
                throw new NotSupportedException("Comments are currently disabled. Setup ConfigFileSettings.CommentChars property to enable them.");
            }
            IniFileCommentary com;

            if (index > 0 && parent.elements[index - 1] is IniFileCommentary)
            {
                com = ((IniFileCommentary)parent.elements[index - 1]);
                if (comment == "")
                {
                    parent.elements.Remove(com);
                }
                else
                {
                    com.Comment     = comment;
                    com.Intendation = el.Intendation;
                }
            }
            else if (comment != "")
            {
                com             = IniFileCommentary.FromComment(comment);
                com.Intendation = el.Intendation;
                parent.elements.Insert(index, com);
            }
        }
Exemple #2
0
        /// <summary>Parses a single line.</summary>
        /// <param name="line">Text to parse.</param>
        private static IniFileElement ParseLine(string line)
        {
            if (line == null)
            {
                return(null);
            }
            if (line.Contains("\n"))
            {
                throw new ArgumentException("String passed to the ParseLine method cannot contain more than one line.");
            }
            string         trim = line.Trim();
            IniFileElement elem = null;

            if (IniFileBlankLine.IsLineValid(trim))
            {
                elem = new IniFileBlankLine(1);
            }
            else if (IniFileCommentary.IsLineValid(line))
            {
                elem = new IniFileCommentary(line);
            }
            else if (IniFileSectionStart.IsLineValid(trim))
            {
                elem = new IniFileSectionStart(line);
            }
            else if (IniFileValue.IsLineValid(trim))
            {
                elem = new IniFileValue(line);
            }
            return(elem ?? new IniFileElement(line));
        }
Exemple #3
0
        /// <summary>Gets an IniFileCommentary object from commentary text.</summary>
        /// <param name="comment">Commentary text.</param>
        public static IniFileCommentary FromComment(string comment)
        {
            if (IniFileEx.CommentChars.Length == 0)
            {
                throw new NotSupportedException("Comments are disabled. Set the IniFileEx.CommentChars property to turn them on.");
            }

            IniFileCommentary ret = new IniFileCommentary();

            ret.fComment    = comment;
            ret.CommentChar = IniFileEx.CommentChars[0];
            return(ret);
        }