mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 11:44:57 +00:00
feat: Adding methods for reading DateTimes from XML
This commit is contained in:
@@ -414,7 +414,7 @@ namespace ICD.Common.Utils.Xml
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the element content as a short.
|
||||
/// Parses the element content as a TimeSpan.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
@@ -439,6 +439,21 @@ namespace ICD.Common.Utils.Xml
|
||||
return IcdXmlConvert.ToTimeSpan(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the element content as a DateTime.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static DateTime ReadElementContentAsDateTime(this IcdXmlReader extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
string content = extends.ReadElementContentAsString();
|
||||
return IcdXmlConvert.ToDateTime(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the element content as an enum.
|
||||
/// </summary>
|
||||
|
||||
@@ -481,12 +481,25 @@ namespace ICD.Common.Utils.Xml
|
||||
/// <param name="childElement"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static TimeSpan? ReadChildElementContentAsTimeSpan(string xml, string childElement)
|
||||
public static TimeSpan ReadChildElementContentAsTimeSpan(string xml, string childElement)
|
||||
{
|
||||
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
||||
return reader.ReadElementContentAsTimeSpan();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="childElement"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static DateTime ReadChildElementContentAsDateTime(string xml, string childElement)
|
||||
{
|
||||
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
||||
return reader.ReadElementContentAsDateTime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
@@ -711,6 +724,25 @@ 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 DateTime? TryReadChildElementContentAsDateTime(string xml, string childElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReadChildElementContentAsDateTime(xml, childElement);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the immediate child. Returns default if the child element could not be parsed.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user