blob: ae0cc2ce3683d1754dc09ac2699d54d0e6ee91db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
using System.Globalization;
using System.Xml;
namespace MediaBrowser.Controller.Xml
{
public static class XmlExtensions
{
private static CultureInfo _usCulture = new CultureInfo("en-US");
public static float ReadFloatSafe(this XmlReader reader)
{
string valueString = reader.ReadElementContentAsString();
float value = 0;
if (!string.IsNullOrEmpty(valueString))
{
// float.TryParse is local aware, so it can be probamatic, force us culture
float.TryParse(valueString, NumberStyles.AllowDecimalPoint, _usCulture, out value);
}
return value;
}
public static int ReadIntSafe(this XmlReader reader)
{
string valueString = reader.ReadElementContentAsString();
int value = 0;
if (!string.IsNullOrEmpty(valueString))
{
int.TryParse(valueString, out value);
}
return value;
}
}
}
|