diff --git a/Implab/JSON/JSONXmlReader.cs b/Implab/JSON/JSONXmlReader.cs --- a/Implab/JSON/JSONXmlReader.cs +++ b/Implab/JSON/JSONXmlReader.cs @@ -38,10 +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"); + JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) { m_parser = parser; if (options != null) { @@ -51,7 +49,6 @@ 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; @@ -59,7 +56,6 @@ namespace Implab.JSON { m_flattenArrays = false; m_arrayItemName = "item"; m_nameTable = new NameTable(); - m_disposeParser = false; } } @@ -306,17 +302,23 @@ namespace Implab.JSON { 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); } } } diff --git a/Implab/JSON/JSONXmlReaderOptions.cs b/Implab/JSON/JSONXmlReaderOptions.cs --- a/Implab/JSON/JSONXmlReaderOptions.cs +++ b/Implab/JSON/JSONXmlReaderOptions.cs @@ -58,12 +58,5 @@ namespace Implab.JSON { set; } - /// - /// Флаг, означающий, что неужно освободить парсер по окончанию работы. - /// - public bool DisposeParser { - get; - set; - } } }