mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Support reading primitive type double in IcdXmlReader and XmlUtils
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -448,6 +448,19 @@ namespace ICD.Common.Utils.Xml
|
||||
return reader.ReadElementContentAsFloat();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="childElement"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static double ReadChildElementContentAsDouble(string xml, string childElement)
|
||||
{
|
||||
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
||||
return reader.ReadElementContentAsDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
@@ -663,6 +676,29 @@ namespace ICD.Common.Utils.Xml
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the immediate child. Returns null if the child element was not found.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="childElement"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static double? TryReadChildElementContentAsDouble(string xml, string childElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReadChildElementContentAsDouble(xml, childElement);
|
||||
}
|
||||
catch (IcdXmlException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child. Returns null if the child element was not found.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user