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 diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:11:07 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Thu Mar 19 20:12:29 2009 +0000
     1.3 @@ -381,14 +381,26 @@
     1.4  				
     1.5  		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
     1.6  		{
     1.7 -			try
     1.8 -			{
     1.9 -				return int.Parse(elem.GetAttribute(attributeName));
    1.10 -			}
    1.11 -			catch(FormatException)
    1.12 -			{
    1.13 -				throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
    1.14 +			string attribValue = elem.GetAttribute(attributeName);
    1.15 +			int intValue = int.MaxValue;
    1.16 +			
    1.17 +			if ("INF".Equals(attribValue))
    1.18 +			{
    1.19 +				intValue = WarFoundryCore.INFINITY;
    1.20  			}
    1.21 +			else
    1.22 +			{
    1.23 +				try
    1.24 +				{
    1.25 +					intValue = int.Parse(attribValue);
    1.26 +				}
    1.27 +				catch(FormatException)
    1.28 +				{
    1.29 +					throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
    1.30 +				}
    1.31 +			}
    1.32 +			
    1.33 +			return intValue;
    1.34  		}
    1.35  						
    1.36  		private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)