diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-14 16:45:11 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-14 16:45:11 -0400 |
| commit | 2e03cb0916f69b324fe654f92f1642b21eb92005 (patch) | |
| tree | 5472b527c627a079fcd1b1398cfc8fa8824c0836 /MediaBrowser.Controller/Xml/XmlExtensions.cs | |
| parent | 5f5f2838b1931a2cf426b778755a417cc662b46f (diff) | |
Improved loading performance even more by switching from XmlDocument to XmlReader. Also added more api improvements.
Diffstat (limited to 'MediaBrowser.Controller/Xml/XmlExtensions.cs')
| -rw-r--r-- | MediaBrowser.Controller/Xml/XmlExtensions.cs | 65 |
1 files changed, 16 insertions, 49 deletions
diff --git a/MediaBrowser.Controller/Xml/XmlExtensions.cs b/MediaBrowser.Controller/Xml/XmlExtensions.cs index 4f753a3f8..ae0cc2ce3 100644 --- a/MediaBrowser.Controller/Xml/XmlExtensions.cs +++ b/MediaBrowser.Controller/Xml/XmlExtensions.cs @@ -6,69 +6,36 @@ namespace MediaBrowser.Controller.Xml {
public static class XmlExtensions
{
- public static int SafeGetInt32(this XmlNode node)
- {
- return SafeGetInt32(node, 0);
- }
+ private static CultureInfo _usCulture = new CultureInfo("en-US");
- public static int SafeGetInt32(this XmlNode node, int defaultInt)
+ public static float ReadFloatSafe(this XmlReader reader)
{
- if (node != null && node.InnerText.Length > 0)
- {
- int rval;
- if (Int32.TryParse(node.InnerText, out rval))
- {
- return rval;
- }
-
- }
- return defaultInt;
- }
+ string valueString = reader.ReadElementContentAsString();
- private static CultureInfo _usCulture = new CultureInfo("en-US");
+ float value = 0;
- public static float SafeGetSingle(this XmlNode rvalNode, float minValue, float maxValue)
- {
- if (rvalNode.InnerText.Length > 0)
+ if (!string.IsNullOrEmpty(valueString))
{
- float rval;
// float.TryParse is local aware, so it can be probamatic, force us culture
- if (float.TryParse(rvalNode.InnerText, NumberStyles.AllowDecimalPoint, _usCulture, out rval))
- {
- if (rval >= minValue && rval <= maxValue)
- {
- return rval;
- }
- }
-
+ float.TryParse(valueString, NumberStyles.AllowDecimalPoint, _usCulture, out value);
}
- return minValue;
- }
-
- public static float SafeGetSingle(this XmlNode doc, string path, float minValue, float maxValue)
- {
- XmlNode rvalNode = doc.SelectSingleNode(path);
- if (rvalNode != null)
- {
- rvalNode.SafeGetSingle(minValue, maxValue);
- }
- return minValue;
+ return value;
}
-
- public static string SafeGetString(this XmlNode node)
+ public static int ReadIntSafe(this XmlReader reader)
{
- return SafeGetString(node, null);
- }
+ string valueString = reader.ReadElementContentAsString();
- public static string SafeGetString(this XmlNode node, string defaultValue)
- {
- if (node != null && node.InnerText.Length > 0)
+ int value = 0;
+
+ if (!string.IsNullOrEmpty(valueString))
{
- return node.InnerText;
+
+ int.TryParse(valueString, out value);
}
- return defaultValue;
+
+ return value;
}
}
}
|
