Add TryReadInt to XmlReaderExtensions

This commit is contained in:
Patrick Barron
2023-10-06 15:35:26 -04:00
parent 8a7a1cc723
commit 0e51ffa169
5 changed files with 62 additions and 166 deletions

View File

@@ -26,6 +26,19 @@ public static class XmlReaderExtensions
return reader.ReadElementContentAsString().Trim();
}
/// <summary>
/// Reads an int from the current node.
/// </summary>
/// <param name="reader">The <see cref="XmlReader"/>.</param>
/// <param name="value">The parsed <c>int</c>.</param>
/// <returns>A value indicating whether the parsing succeeded.</returns>
public static bool TryReadInt(this XmlReader reader, out int value)
{
ArgumentNullException.ThrowIfNull(reader);
return int.TryParse(reader.ReadElementContentAsString(), CultureInfo.InvariantCulture, out value);
}
/// <summary>
/// Parses a <see cref="DateTime"/> from the current node.
/// </summary>