mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-13 20:47:24 +00:00
feat: Adding short parsing methods to XML utils
This commit is contained in:
parent
ad7176506d
commit
e222ce424b
2 changed files with 47 additions and 0 deletions
|
|
@ -382,6 +382,21 @@ namespace ICD.Common.Utils.Xml
|
||||||
return ushort.Parse(content);
|
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>
|
/// <summary>
|
||||||
/// Parses the element content as an enum.
|
/// Parses the element content as an enum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -406,6 +406,19 @@ namespace ICD.Common.Utils.Xml
|
||||||
return reader.ReadElementContentAsUShort();
|
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>
|
/// <summary>
|
||||||
/// Gets the content of an immediate child.
|
/// Gets the content of an immediate child.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets the content of the immediate child. Returns null if the child element was not found.
|
/// Gets the content of the immediate child. Returns null if the child element was not found.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue