Mercurial > pub > ImplabNet
changeset 64:a809805210d1
small refactoring
author | cin |
---|---|
date | Wed, 25 Jun 2014 04:44:53 +0400 |
parents | 908b4f340c69 |
children | 653c4e04968b |
files | Implab/JSON/JSONXmlReader.cs Implab/JSON/JSONXmlReaderOptions.cs |
diffstat | 2 files changed, 13 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/Implab/JSON/JSONXmlReader.cs Mon Jun 23 17:34:40 2014 +0400 +++ b/Implab/JSON/JSONXmlReader.cs Wed Jun 25 04:44:53 2014 +0400 @@ -38,10 +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"); + JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) { m_parser = parser; if (options != null) { @@ -51,7 +49,6 @@ 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; @@ -59,7 +56,6 @@ m_flattenArrays = false; m_arrayItemName = "item"; m_nameTable = new NameTable(); - m_disposeParser = false; } } @@ -306,17 +302,23 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (m_disposeParser) - m_parser.Dispose(); + m_parser.Dispose(); } base.Dispose(disposing); } + public static JSONXmlReader Create(string file, JSONXmlReaderOptions options) { + return Create(File.OpenText(file), options); + } - public static JSONXmlReader OpenFile(string file, JSONXmlReaderOptions options) { - var stream = File.OpenText(file); - var parser = new JSONParser(stream, true); - return new JSONXmlReader(parser, options); + public static JSONXmlReader Create(TextReader reader, JSONXmlReaderOptions options) { + return new JSONXmlReader(new JSONParser(reader, true), options); + } + + public static JSONXmlReader Create(Stream stream, JSONXmlReaderOptions options) { + Safe.ArgumentNotNull(stream, "stream"); + // HACK don't dispose StreaReader to keep stream opened + return Create(new StreamReader(stream), options); } } }
--- a/Implab/JSON/JSONXmlReaderOptions.cs Mon Jun 23 17:34:40 2014 +0400 +++ b/Implab/JSON/JSONXmlReaderOptions.cs Wed Jun 25 04:44:53 2014 +0400 @@ -58,12 +58,5 @@ set; } - /// <summary> - /// Флаг, означающий, что неужно освободить парсер по окончанию работы. - /// </summary> - public bool DisposeParser { - get; - set; - } } }