feat: Adding short parsing methods to XML utils

This commit is contained in:
Rashod Davis
2018-11-27 16:46:26 -05:00
committed by Chris Cameron
parent ad7176506d
commit e222ce424b
2 changed files with 47 additions and 0 deletions

View File

@@ -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>

View File

@@ -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>