# HG changeset patch # User IBBoard # Date 1237493549 0 # Node ID 05c6745cc660804b9f87f7c2e79738f356ec9f65 # Parent 548cfc776f54aef817655608d3da33fc68708635 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 diff -r 548cfc776f54 -r 05c6745cc660 api/Factories/Xml/WarFoundryXmlFactory.cs --- 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)