changeset 39:05c6745cc660

Re #47: Remove magic numbers * Replace "-1" magic number with WarFoundryCore.INFINITY * Use INFINITY instead of -1 in code * Handle and parse INF as a special value in XML Factory
author IBBoard <dev@ibboard.co.uk>
date Thu, 19 Mar 2009 20:12:29 +0000
parents 548cfc776f54
children 3664eee50390
files api/Factories/Xml/WarFoundryXmlFactory.cs
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:11:07 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:12:29 2009 +0000
@@ -381,14 +381,26 @@
 				
 		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
 		{
-			try
-			{
-				return int.Parse(elem.GetAttribute(attributeName));
-			}
-			catch(FormatException)
-			{
-				throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
+			string attribValue = elem.GetAttribute(attributeName);
+			int intValue = int.MaxValue;
+			
+			if ("INF".Equals(attribValue))
+			{
+				intValue = WarFoundryCore.INFINITY;
 			}
+			else
+			{
+				try
+				{
+					intValue = int.Parse(attribValue);
+				}
+				catch(FormatException)
+				{
+					throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
+				}
+			}
+			
+			return intValue;
 		}
 						
 		private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)