comparison api/Factories/Xml/WarFoundryXmlFactory.cs @ 40:3664eee50390

Fixes #47 - remove magic numbers * Create "infinity" in core types * Redefine special core types without trying to use non-existant INF for Integers * Use new types in Cats and Race * Remove special handling of INF when parsing an integer attribute Closes #46 - Resolve problems using custom restrictions of decimal and double * New schemas seem to work without exceptioning
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Mar 2009 17:04:33 +0000
parents 05c6745cc660
children 422ddd5fedd1
comparison
equal deleted inserted replaced
39:05c6745cc660 40:3664eee50390
379 return new Category(id, name, minPts, maxPts, minPc, maxPc, minChoices, maxChoices, baseValue, incValue, incAmount); 379 return new Category(id, name, minPts, maxPts, minPc, maxPc, minChoices, maxChoices, baseValue, incValue, incAmount);
380 } 380 }
381 381
382 private int GetIntValueFromAttribute(XmlElement elem, string attributeName) 382 private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
383 { 383 {
384 string attribValue = elem.GetAttribute(attributeName); 384 try
385 int intValue = int.MaxValue; 385 {
386 386 return int.Parse(elem.GetAttribute(attributeName));
387 if ("INF".Equals(attribValue)) 387 }
388 { 388 catch(FormatException)
389 intValue = WarFoundryCore.INFINITY; 389 {
390 } 390 throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
391 else 391 }
392 {
393 try
394 {
395 intValue = int.Parse(attribValue);
396 }
397 catch(FormatException)
398 {
399 throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid number", attributeName, elem.Name, elem.GetAttribute("id")));
400 }
401 }
402
403 return intValue;
404 } 392 }
405 393
406 private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system) 394 private UnitType CreateUnitTypeFromElement(XmlElement elem, Race parentRace, GameSystem system)
407 { 395 {
408 string id = elem.GetAttribute("id"); 396 string id = elem.GetAttribute("id");