mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 13:45:05 +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>
|
/// <summary>
|
||||||
/// Parses the element content as a short.
|
/// Parses the element content as a TimeSpan.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="extends"></param>
|
/// <param name="extends"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -439,6 +439,21 @@ namespace ICD.Common.Utils.Xml
|
|||||||
return IcdXmlConvert.ToTimeSpan(content);
|
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>
|
/// <summary>
|
||||||
/// Parses the element content as an enum.
|
/// Parses the element content as an enum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -481,12 +481,25 @@ namespace ICD.Common.Utils.Xml
|
|||||||
/// <param name="childElement"></param>
|
/// <param name="childElement"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static TimeSpan? ReadChildElementContentAsTimeSpan(string xml, string childElement)
|
public static TimeSpan ReadChildElementContentAsTimeSpan(string xml, string childElement)
|
||||||
{
|
{
|
||||||
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
||||||
return reader.ReadElementContentAsTimeSpan();
|
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>
|
/// <summary>
|
||||||
/// Gets the content of an immediate child.
|
/// Gets the content of an immediate child.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets the content of the immediate child. Returns default if the child element could not be parsed.
|
/// Gets the content of the immediate child. Returns default if the child element could not be parsed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user