# HG changeset patch # User cin # Date 2014-06-23 13:34:40 # Node ID 908b4f340c6992fa9bcae84fb36130c6bf25d765 # Parent 62b440d46313099dffc61de8ebaba7d78613f06c fixed: JSONXmlReader.Value returns invalid textual representation for numbers. diff --git a/Implab/JSON/JSONXmlReader.cs b/Implab/JSON/JSONXmlReader.cs --- a/Implab/JSON/JSONXmlReader.cs +++ b/Implab/JSON/JSONXmlReader.cs @@ -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 @@ namespace Implab.JSON { 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 @@ namespace Implab.JSON { 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 @@ namespace Implab.JSON { m_flattenArrays = false; m_arrayItemName = "item"; m_nameTable = new NameTable(); + m_disposeParser = false; } } @@ -72,7 +76,7 @@ namespace Implab.JSON { public override int Depth { get { - return m_localNameStack.Count+m_depthCorrection; + return m_localNameStack.Count + m_depthCorrection; } } @@ -270,7 +274,14 @@ namespace Implab.JSON { } 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 @@ namespace Implab.JSON { } public override void Close() { - + } protected override void Dispose(bool disposing) { if (disposing) { - m_parser.Dispose(); + if (m_disposeParser) + m_parser.Dispose(); } base.Dispose(disposing); } diff --git a/Implab/JSON/JSONXmlReaderOptions.cs b/Implab/JSON/JSONXmlReaderOptions.cs --- a/Implab/JSON/JSONXmlReaderOptions.cs +++ b/Implab/JSON/JSONXmlReaderOptions.cs @@ -57,5 +57,13 @@ namespace Implab.JSON { get; set; } + + /// + /// Флаг, означающий, что неужно освободить парсер по окончанию работы. + /// + public bool DisposeParser { + get; + set; + } } }