##// END OF EJS Templates
small refactoring
cin -
r64:a809805210d1 default
parent child
Show More
@@ -38,10 +38,8 namespace Implab.JSON {
38 38 readonly bool m_flattenArrays;
39 39 readonly string m_arrayItemName;
40 40 readonly XmlNameTable m_nameTable;
41 readonly bool m_disposeParser;
42 41
43 public JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) {
44 Safe.ArgumentNotNull(parser, "parser");
42 JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) {
45 43 m_parser = parser;
46 44
47 45 if (options != null) {
@@ -51,7 +49,6 namespace Implab.JSON {
51 49 m_flattenArrays = options.FlattenArrays;
52 50 m_arrayItemName = options.ArrayItemName ?? "item";
53 51 m_nameTable = options.NameTable ?? new NameTable();
54 m_disposeParser = options.DisposeParser;
55 52 } else {
56 53 m_prefix = String.Empty;
57 54 m_namespaceUri = String.Empty;
@@ -59,7 +56,6 namespace Implab.JSON {
59 56 m_flattenArrays = false;
60 57 m_arrayItemName = "item";
61 58 m_nameTable = new NameTable();
62 m_disposeParser = false;
63 59 }
64 60 }
65 61
@@ -306,17 +302,23 namespace Implab.JSON {
306 302
307 303 protected override void Dispose(bool disposing) {
308 304 if (disposing) {
309 if (m_disposeParser)
310 305 m_parser.Dispose();
311 306 }
312 307 base.Dispose(disposing);
313 308 }
314 309
310 public static JSONXmlReader Create(string file, JSONXmlReaderOptions options) {
311 return Create(File.OpenText(file), options);
312 }
315 313
316 public static JSONXmlReader OpenFile(string file, JSONXmlReaderOptions options) {
317 var stream = File.OpenText(file);
318 var parser = new JSONParser(stream, true);
319 return new JSONXmlReader(parser, options);
314 public static JSONXmlReader Create(TextReader reader, JSONXmlReaderOptions options) {
315 return new JSONXmlReader(new JSONParser(reader, true), options);
316 }
317
318 public static JSONXmlReader Create(Stream stream, JSONXmlReaderOptions options) {
319 Safe.ArgumentNotNull(stream, "stream");
320 // HACK don't dispose StreaReader to keep stream opened
321 return Create(new StreamReader(stream), options);
320 322 }
321 323 }
322 324 }
@@ -58,12 +58,5 namespace Implab.JSON {
58 58 set;
59 59 }
60 60
61 /// <summary>
62 /// Флаг, означающий, что неужно освободить парсер по окончанию работы.
63 /// </summary>
64 public bool DisposeParser {
65 get;
66 set;
67 61 }
68 62 }
69 }
General Comments 0
You need to be logged in to leave comments. Login now