mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-06 08:16:19 +00:00
feat: Adding short parsing methods to XML utils
This commit is contained in:
committed by
Chris Cameron
parent
ad7176506d
commit
e222ce424b
@@ -382,6 +382,21 @@ namespace ICD.Common.Utils.Xml
|
||||
return ushort.Parse(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the element content as a short.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static short ReadElementContentAsShort(this IcdXmlReader extends)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
string content = extends.ReadElementContentAsString();
|
||||
return short.Parse(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the element content as an enum.
|
||||
/// </summary>
|
||||
|
||||
@@ -406,6 +406,19 @@ namespace ICD.Common.Utils.Xml
|
||||
return reader.ReadElementContentAsUShort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
/// <param name="xml"></param>
|
||||
/// <param name="childElement"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static short ReadChildElementContentAsShort(string xml, string childElement)
|
||||
{
|
||||
using (IcdXmlReader reader = GetChildElement(xml, childElement))
|
||||
return reader.ReadElementContentAsShort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of an immediate child.
|
||||
/// </summary>
|
||||
@@ -566,6 +579,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 short? TryReadChildElementContentAsShort(string xml, string childElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReadChildElementContentAsShort(xml, childElement);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the immediate child. Returns null if the child element was not found.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user