2012-07-20 04:22:44 +02:00
|
|
|
|
using System.Globalization;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Xml
|
|
|
|
|
{
|
|
|
|
|
public static class XmlExtensions
|
|
|
|
|
{
|
2012-07-14 22:45:11 +02:00
|
|
|
|
private static CultureInfo _usCulture = new CultureInfo("en-US");
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads a float from the current element of an XmlReader
|
|
|
|
|
/// </summary>
|
2012-08-20 23:48:11 +02:00
|
|
|
|
public static float ReadFloatSafe(this XmlReader reader)
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-08-20 23:48:11 +02:00
|
|
|
|
string valueString = reader.ReadElementContentAsString();
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-14 22:45:11 +02:00
|
|
|
|
float value = 0;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(valueString))
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
|
|
|
|
// float.TryParse is local aware, so it can be probamatic, force us culture
|
2012-07-14 22:45:11 +02:00
|
|
|
|
float.TryParse(valueString, NumberStyles.AllowDecimalPoint, _usCulture, out value);
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 22:45:11 +02:00
|
|
|
|
return value;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads an int from the current element of an XmlReader
|
|
|
|
|
/// </summary>
|
2012-08-20 23:48:11 +02:00
|
|
|
|
public static int ReadIntSafe(this XmlReader reader)
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-08-20 23:48:11 +02:00
|
|
|
|
string valueString = reader.ReadElementContentAsString();
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-14 22:45:11 +02:00
|
|
|
|
int value = 0;
|
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(valueString))
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-07-14 22:45:11 +02:00
|
|
|
|
|
|
|
|
|
int.TryParse(valueString, out value);
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
2012-07-14 22:45:11 +02:00
|
|
|
|
|
|
|
|
|
return value;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|