diff Implab/JSON/JSONXmlReader.cs @ 63:908b4f340c69

fixed: JSONXmlReader.Value returns invalid textual representation for numbers.
author cin
date Mon, 23 Jun 2014 17:34:40 +0400
parents 10c7337d29e7
children a809805210d1
line wrap: on
line diff
--- a/Implab/JSON/JSONXmlReader.cs	Sun Jun 22 04:14:02 2014 +0400
+++ b/Implab/JSON/JSONXmlReader.cs	Mon Jun 23 17:34:40 2014 +0400
@@ -2,6 +2,7 @@
 using Implab.Parsing;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.IO;
 using System.Linq;
 using System.Text;
@@ -37,7 +38,8 @@
         readonly bool m_flattenArrays;
         readonly string m_arrayItemName;
         readonly XmlNameTable m_nameTable;
-        
+        readonly bool m_disposeParser;
+
         public JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) {
             Safe.ArgumentNotNull(parser, "parser");
             m_parser = parser;
@@ -49,6 +51,7 @@
                 m_flattenArrays = options.FlattenArrays;
                 m_arrayItemName = options.ArrayItemName ?? "item";
                 m_nameTable = options.NameTable ?? new NameTable();
+                m_disposeParser = options.DisposeParser;
             } else {
                 m_prefix = String.Empty;
                 m_namespaceUri = String.Empty;
@@ -56,6 +59,7 @@
                 m_flattenArrays = false;
                 m_arrayItemName = "item";
                 m_nameTable = new NameTable();
+                m_disposeParser = false;
             }
         }
 
@@ -72,7 +76,7 @@
 
         public override int Depth {
             get {
-                return m_localNameStack.Count+m_depthCorrection;
+                return m_localNameStack.Count + m_depthCorrection;
             }
         }
 
@@ -270,7 +274,14 @@
         }
 
         public override string Value {
-            get { return m_parser.ElementValue == null ? String.Empty : m_parser.ElementValue.ToString(); }
+            get {
+                if (m_parser.ElementValue == null)
+                    return String.Empty;
+                if (Convert.GetTypeCode(m_parser.ElementValue) == TypeCode.Double)
+                    return ((double)m_parser.ElementValue).ToString(CultureInfo.InvariantCulture);
+                else
+                    return (string)m_parser.ElementValue;
+            }
         }
 
         void SetLocalName(string name) {
@@ -290,12 +301,13 @@
         }
 
         public override void Close() {
-            
+
         }
 
         protected override void Dispose(bool disposing) {
             if (disposing) {
-                m_parser.Dispose();
+                if (m_disposeParser)
+                    m_parser.Dispose();
             }
             base.Dispose(disposing);
         }