diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c05085..b4d5b98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added IcdTimeZoneInfo, a very light implementation of System.TimeZoneInfo for the .NET Compact Framework - Added ThreadedWorkerQueue - a threadsafe way to enqueue items and have a worker thread process them one at a time - Added eDaysOfWeek flags enum + - Added support for reading the primitive type double to IcdXmlReader and XmlUtils ### Changed - Repeater changed to use configured callbacks instead of a dumb event diff --git a/ICD.Common.Utils/Xml/IcdXmlReader.cs b/ICD.Common.Utils/Xml/IcdXmlReader.cs index 86d25ec..e7da138 100644 --- a/ICD.Common.Utils/Xml/IcdXmlReader.cs +++ b/ICD.Common.Utils/Xml/IcdXmlReader.cs @@ -189,6 +189,13 @@ namespace ICD.Common.Utils.Xml return float.Parse(value); } + public double ReadElementContentAsDouble() + { + // ReadElementContentAsDouble() logs and throws... + string value = ReadElementContentAsString(); + return double.Parse(value); + } + public bool ReadElementContentAsBoolean() { // ReadElementContentAsBoolean() is too case sensitive diff --git a/ICD.Common.Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Xml/XmlUtils.cs index 0a5777d..cc546a2 100644 --- a/ICD.Common.Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Xml/XmlUtils.cs @@ -448,6 +448,19 @@ namespace ICD.Common.Utils.Xml return reader.ReadElementContentAsFloat(); } + /// + /// Gets the content of an immediate child. + /// + /// + /// + /// + [PublicAPI] + public static double ReadChildElementContentAsDouble(string xml, string childElement) + { + using (IcdXmlReader reader = GetChildElement(xml, childElement)) + return reader.ReadElementContentAsDouble(); + } + /// /// Gets the content of an immediate child. /// @@ -663,6 +676,29 @@ namespace ICD.Common.Utils.Xml } } + /// + /// Gets the content of the immediate child. Returns null if the child element was not found. + /// + /// + /// + /// + [PublicAPI] + public static double? TryReadChildElementContentAsDouble(string xml, string childElement) + { + try + { + return ReadChildElementContentAsDouble(xml, childElement); + } + catch (IcdXmlException) + { + return null; + } + catch (FormatException) + { + return null; + } + } + /// /// Gets the content of an immediate child. Returns null if the child element was not found. ///