You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Controller/Xml/XmlExtensions.cs

47 lines
1.3 KiB

using System.Globalization;
13 years ago
using System.Xml;
namespace MediaBrowser.Controller.Xml
{
public static class XmlExtensions
{
private static CultureInfo _usCulture = new CultureInfo("en-US");
13 years ago
/// <summary>
/// Reads a float from the current element of an XmlReader
/// </summary>
public static float ReadFloatSafe(this XmlReader reader)
13 years ago
{
string valueString = reader.ReadElementContentAsString();
13 years ago
float value = 0;
13 years ago
if (!string.IsNullOrWhiteSpace(valueString))
13 years ago
{
// float.TryParse is local aware, so it can be probamatic, force us culture
float.TryParse(valueString, NumberStyles.AllowDecimalPoint, _usCulture, out value);
13 years ago
}
return value;
13 years ago
}
/// <summary>
/// Reads an int from the current element of an XmlReader
/// </summary>
public static int ReadIntSafe(this XmlReader reader)
13 years ago
{
string valueString = reader.ReadElementContentAsString();
13 years ago
int value = 0;
if (!string.IsNullOrWhiteSpace(valueString))
13 years ago
{
int.TryParse(valueString, out value);
13 years ago
}
return value;
13 years ago
}
}
}