changeset 3:3c26f463977a

Re #7 - Add INI parsing tests * Make IniSection throw a new DuplicateIniLineException to make testing of duplicates easier
author IBBoard <dev@ibboard.co.uk>
date Sun, 18 Jan 2009 14:18:07 +0000
parents 2dde4c1d19d9
children 01fc09ab63e2
files DuplicateIniLineException.cs IBBoard.Ini.mdp IniSection.cs
diffstat 3 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DuplicateIniLineException.cs	Sun Jan 18 14:18:07 2009 +0000
@@ -0,0 +1,18 @@
+// This file (DuplicateIniLineException.cs) is a part of [PROJECT NAME] and is copyright 2009 IBBoard.
+//
+// The file and the library/program it is in are licensed under the GNU LGPL license. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+
+namespace IBBoard.Ini
+{
+	/// <summary>
+	/// An exception that indicates that a second line has been added to an IniSection that contained the same key as an existing line
+	/// </summary>
+	public class DuplicateIniLineException : ArgumentException
+	{		
+		public DuplicateIniLineException(string sectionName, string lineName) : base("The section [" + sectionName + "] already contained a line with the key '" + lineName + "'")
+		{
+		}
+	}
+}
--- a/IBBoard.Ini.mdp	Mon Jan 12 20:34:07 2009 +0000
+++ b/IBBoard.Ini.mdp	Sun Jan 18 14:18:07 2009 +0000
@@ -28,6 +28,7 @@
     <File name="IIniLine.cs" subtype="Code" buildaction="Compile" />
     <File name="IniBlankLine.cs" subtype="Code" buildaction="Compile" />
     <File name="IniCommentLine.cs" subtype="Code" buildaction="Compile" />
+    <File name="DuplicateIniLineException.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
--- a/IniSection.cs	Mon Jan 12 20:34:07 2009 +0000
+++ b/IniSection.cs	Sun Jan 18 14:18:07 2009 +0000
@@ -87,7 +87,9 @@
 
 		/// <summary>
 		/// Adds an <see cref=" IIniLine"/> to the <code>IniSection</code>. If <code>iniLine</code> is also an <see cref=" IniKeyValuePairLine"/>
-		/// then it becomes available through <code>this[key]</code>
+		/// then it becomes available through <code>this[key]</code>.
+		/// <p>
+		/// Throws a <see cref=" DuplicateIniException"/> if the line is a <see cref=" IniKeyValuePairLine"/> and the key already exists
 		/// </summary>
 		public void AddIniLine(IIniLine iniLine)
 		{
@@ -102,7 +104,7 @@
 				}
 				else
 				{
-					throw new ArgumentException("The key '"+key+"' was already defined in ["+Name+"]");
+					throw new DuplicateIniLineException(Name, key);
 				}
 			}