public static decimal SafeGetDecimalFromElement(XElement element, string elementName) { XElement x = GetElement(element, elementName); decimal result; if (!decimal.TryParse(x.Value, out result)) { throw new InvalidOperationException(string.Format("Decimal not found in element {0}.", elementName)); } return result; }