Mercurial > repos > IBBoard
diff Xml/XmlTools.cs @ 63:8fe11cd7d3bf
Re #25: Enum parsing
* Extract enum parsing to separate class
* Add more info to XmlTools exceptions and use new class
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 30 Nov 2009 21:00:05 +0000 |
parents | 6e46a62ad9b8 |
children | 7ca4acc659bb de0ed24eb961 |
line wrap: on
line diff
--- a/Xml/XmlTools.cs Mon Nov 30 20:46:54 2009 +0000 +++ b/Xml/XmlTools.cs Mon Nov 30 21:00:05 2009 +0000 @@ -110,13 +110,15 @@ public static T GetEnumValueFromAttribute<T>(XmlElement elem, string attributeName, bool ignoreCase) { + string attribValue = elem.GetAttribute (attributeName); + try { - return (T) Enum.Parse(typeof (T), elem.GetAttribute(attributeName), ignoreCase); + return EnumTools.ParseEnum<T>(attribValue, ignoreCase); } catch(ArgumentException) { - throw new FormatException(String.Format("Attribute '{0}' of {1} with ID {2} was not a valid {3} enum", attributeName, elem.Name, elem.GetAttribute("id"), typeof(T).Name)); + throw new FormatException(String.Format("Attribute '{0}' with value {1} for {2} with ID '{3}' was not a valid {4} enum", attributeName, attribValue, elem.Name, elem.GetAttribute("id"), typeof(T).Name)); } }