Example #1
0
        private void SetComment(IniElement el, string comment)
        {
            var index = Parent.Elements.IndexOf(el);

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

            if (index > 0 && Parent.Elements[index - 1] is IniCommentary)
            {
                com = ((IniCommentary)Parent.Elements[index - 1]);
                if (comment == "")
                {
                    Parent.Elements.Remove(com);
                }
                else
                {
                    com.Comment     = comment;
                    com.Indentation = el.Indentation;
                }
            }
            else if (comment != "")
            {
                com             = IniCommentary.FromComment(comment);
                com.Indentation = el.Indentation;
                Parent.Elements.Insert(index, com);
            }
        }
Example #2
0
        public static IniElement 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.");
            }
            var        trim = line.Trim();
            IniElement elem = null;

            if (IniBlankLine.IsLineValid(trim))
            {
                elem = new IniBlankLine(1);
            }
            else if (IniCommentary.IsLineValid(line))
            {
                elem = new IniCommentary(line);
            }
            else if (IniSectionStart.IsLineValid(trim))
            {
                elem = new IniSectionStart(line);
            }
            else if (IniValue.IsLineValid(trim))
            {
                elem = new IniValue(line);
            }
            return(elem ?? new IniElement(line));
        }
Example #3
0
        public static IniCommentary FromComment(string comment)
        {
            if (IniSettings.CommentChars.Length == 0)
            {
                throw new NotSupportedException("Comments are disabled. Set the IniSettings.CommentChars property to turn them on.");
            }
            var ret = new IniCommentary();

            ret._comment    = comment;
            ret.CommentChar = IniSettings.CommentChars[0];
            return(ret);
        }
Example #4
0
		public static IniElement 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.");
			var trim = line.Trim();
			IniElement elem = null;
			if (IniBlankLine.IsLineValid(trim))
				elem = new IniBlankLine(1);
			else if (IniCommentary.IsLineValid(line))
				elem = new IniCommentary(line);
			else if (IniSectionStart.IsLineValid(trim))
				elem = new IniSectionStart(line);
			else if (IniValue.IsLineValid(trim))
				elem = new IniValue(line);
			return elem ?? new IniElement(line);
		}
Example #5
0
		public static IniCommentary FromComment(string comment)
		{
			if (IniSettings.CommentChars.Length == 0)
				throw new NotSupportedException("Comments are disabled. Set the IniSettings.CommentChars property to turn them on.");
			var ret = new IniCommentary();
			ret._comment = comment;
			ret.CommentChar = IniSettings.CommentChars[0];
			return ret;
		}
Example #6
0
        public void InsertComment(string comment)
        {
            var com = IniCommentary.FromComment(comment);

            Parent.Elements.Add(com);
        }