Mercurial > pub > ImplabNet
changeset 63:908b4f340c69
fixed: JSONXmlReader.Value returns invalid textual representation for numbers.
author | cin |
---|---|
date | Mon, 23 Jun 2014 17:34:40 +0400 |
parents | 62b440d46313 |
children | a809805210d1 |
files | Implab/JSON/JSONXmlReader.cs Implab/JSON/JSONXmlReaderOptions.cs |
diffstat | 2 files changed, 25 insertions(+), 5 deletions(-) [+] |
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); }
--- a/Implab/JSON/JSONXmlReaderOptions.cs Sun Jun 22 04:14:02 2014 +0400 +++ b/Implab/JSON/JSONXmlReaderOptions.cs Mon Jun 23 17:34:40 2014 +0400 @@ -57,5 +57,13 @@ get; set; } + + /// <summary> + /// Флаг, означающий, что неужно освободить парсер по окончанию работы. + /// </summary> + public bool DisposeParser { + get; + set; + } } }