JsonData.cs 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. #region Header
  2. /**
  3. * JsonData.cs
  4. * Generic type to hold JSON data (objects, arrays, and so on). This is
  5. * the default type returned by JsonMapper.ToObject().
  6. *
  7. * The authors disclaim copyright to this source code. For more details, see
  8. * the COPYING file included with this distribution.
  9. **/
  10. #endregion
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Collections.Specialized;
  15. using System.IO;
  16. namespace LitJson
  17. {
  18. public sealed class JsonData : IJsonWrapper, IEquatable<JsonData>
  19. {
  20. #region Fields
  21. private IList<JsonData> inst_array;
  22. private bool inst_boolean;
  23. private double inst_double;
  24. private int inst_int;
  25. private long inst_long;
  26. private IDictionary<string, JsonData> inst_object;
  27. private string inst_string;
  28. private string json;
  29. private JsonType type;
  30. // Used to implement the IOrderedDictionary interface
  31. private IList<KeyValuePair<string, JsonData>> object_list;
  32. #endregion
  33. #region Properties
  34. public int Count {
  35. get { return EnsureCollection ().Count; }
  36. }
  37. public bool IsArray {
  38. get { return type == JsonType.Array; }
  39. }
  40. public bool IsBoolean {
  41. get { return type == JsonType.Boolean; }
  42. }
  43. public bool IsDouble {
  44. get { return type == JsonType.Double; }
  45. }
  46. public bool IsInt {
  47. get { return type == JsonType.Int; }
  48. }
  49. public bool IsLong {
  50. get { return type == JsonType.Long; }
  51. }
  52. public bool IsObject {
  53. get { return type == JsonType.Object; }
  54. }
  55. public bool IsString {
  56. get { return type == JsonType.String; }
  57. }
  58. public ICollection<string> Keys {
  59. get { EnsureDictionary (); return inst_object.Keys; }
  60. }
  61. #endregion
  62. #region ICollection Properties
  63. int ICollection.Count {
  64. get {
  65. return Count;
  66. }
  67. }
  68. bool ICollection.IsSynchronized {
  69. get {
  70. return EnsureCollection ().IsSynchronized;
  71. }
  72. }
  73. object ICollection.SyncRoot {
  74. get {
  75. return EnsureCollection ().SyncRoot;
  76. }
  77. }
  78. #endregion
  79. #region IDictionary Properties
  80. bool IDictionary.IsFixedSize {
  81. get {
  82. return EnsureDictionary ().IsFixedSize;
  83. }
  84. }
  85. bool IDictionary.IsReadOnly {
  86. get {
  87. return EnsureDictionary ().IsReadOnly;
  88. }
  89. }
  90. ICollection IDictionary.Keys {
  91. get {
  92. EnsureDictionary ();
  93. IList<string> keys = new List<string> ();
  94. foreach (KeyValuePair<string, JsonData> entity in
  95. object_list) {
  96. keys.Add (entity.Key);
  97. }
  98. return (ICollection) keys;
  99. }
  100. }
  101. ICollection IDictionary.Values {
  102. get {
  103. EnsureDictionary ();
  104. IList<JsonData> values = new List<JsonData> ();
  105. foreach (KeyValuePair<string, JsonData> entity in
  106. object_list) {
  107. values.Add (entity.Value);
  108. }
  109. return (ICollection) values;
  110. }
  111. }
  112. #endregion
  113. #region IJsonWrapper Properties
  114. bool IJsonWrapper.IsArray {
  115. get { return IsArray; }
  116. }
  117. bool IJsonWrapper.IsBoolean {
  118. get { return IsBoolean; }
  119. }
  120. bool IJsonWrapper.IsDouble {
  121. get { return IsDouble; }
  122. }
  123. bool IJsonWrapper.IsInt {
  124. get { return IsInt; }
  125. }
  126. bool IJsonWrapper.IsLong {
  127. get { return IsLong; }
  128. }
  129. bool IJsonWrapper.IsObject {
  130. get { return IsObject; }
  131. }
  132. bool IJsonWrapper.IsString {
  133. get { return IsString; }
  134. }
  135. #endregion
  136. #region IList Properties
  137. bool IList.IsFixedSize {
  138. get {
  139. return EnsureList ().IsFixedSize;
  140. }
  141. }
  142. bool IList.IsReadOnly {
  143. get {
  144. return EnsureList ().IsReadOnly;
  145. }
  146. }
  147. #endregion
  148. #region IDictionary Indexer
  149. object IDictionary.this[object key] {
  150. get {
  151. return EnsureDictionary ()[key];
  152. }
  153. set {
  154. if (! (key is String))
  155. throw new ArgumentException (
  156. "The key has to be a string");
  157. JsonData data = ToJsonData (value);
  158. this[(string) key] = data;
  159. }
  160. }
  161. #endregion
  162. #region IOrderedDictionary Indexer
  163. object IOrderedDictionary.this[int idx] {
  164. get {
  165. EnsureDictionary ();
  166. return object_list[idx].Value;
  167. }
  168. set {
  169. EnsureDictionary ();
  170. JsonData data = ToJsonData (value);
  171. KeyValuePair<string, JsonData> old_entity = object_list[idx];
  172. inst_object[old_entity.Key] = data;
  173. KeyValuePair<string, JsonData> entity =
  174. new KeyValuePair<string, JsonData> (old_entity.Key, data);
  175. object_list[idx] = entity;
  176. }
  177. }
  178. #endregion
  179. #region IList Indexer
  180. object IList.this[int index] {
  181. get {
  182. return EnsureList ()[index];
  183. }
  184. set {
  185. EnsureList ();
  186. JsonData data = ToJsonData (value);
  187. this[index] = data;
  188. }
  189. }
  190. #endregion
  191. #region Public Indexers
  192. public JsonData this[string prop_name] {
  193. get {
  194. EnsureDictionary ();
  195. return inst_object[prop_name];
  196. }
  197. set {
  198. EnsureDictionary ();
  199. KeyValuePair<string, JsonData> entity =
  200. new KeyValuePair<string, JsonData> (prop_name, value);
  201. if (inst_object.ContainsKey (prop_name)) {
  202. for (int i = 0; i < object_list.Count; i++) {
  203. if (object_list[i].Key == prop_name) {
  204. object_list[i] = entity;
  205. break;
  206. }
  207. }
  208. } else
  209. object_list.Add (entity);
  210. inst_object[prop_name] = value;
  211. json = null;
  212. }
  213. }
  214. public JsonData this[int index] {
  215. get {
  216. EnsureCollection ();
  217. if (type == JsonType.Array)
  218. return inst_array[index];
  219. return object_list[index].Value;
  220. }
  221. set {
  222. EnsureCollection ();
  223. if (type == JsonType.Array)
  224. inst_array[index] = value;
  225. else {
  226. KeyValuePair<string, JsonData> entity = object_list[index];
  227. KeyValuePair<string, JsonData> new_entity =
  228. new KeyValuePair<string, JsonData> (entity.Key, value);
  229. object_list[index] = new_entity;
  230. inst_object[entity.Key] = value;
  231. }
  232. json = null;
  233. }
  234. }
  235. #endregion
  236. #region Constructors
  237. public JsonData ()
  238. {
  239. }
  240. public JsonData (bool boolean)
  241. {
  242. type = JsonType.Boolean;
  243. inst_boolean = boolean;
  244. }
  245. public JsonData (double number)
  246. {
  247. type = JsonType.Double;
  248. inst_double = number;
  249. }
  250. public JsonData (int number)
  251. {
  252. type = JsonType.Int;
  253. inst_int = number;
  254. }
  255. public JsonData (long number)
  256. {
  257. type = JsonType.Long;
  258. inst_long = number;
  259. }
  260. public JsonData (object obj)
  261. {
  262. if (obj is Boolean) {
  263. type = JsonType.Boolean;
  264. inst_boolean = (bool) obj;
  265. return;
  266. }
  267. if (obj is Double) {
  268. type = JsonType.Double;
  269. inst_double = (double) obj;
  270. return;
  271. }
  272. if (obj is Int32) {
  273. type = JsonType.Int;
  274. inst_int = (int) obj;
  275. return;
  276. }
  277. if (obj is Int64) {
  278. type = JsonType.Long;
  279. inst_long = (long) obj;
  280. return;
  281. }
  282. if (obj is String) {
  283. type = JsonType.String;
  284. inst_string = (string) obj;
  285. return;
  286. }
  287. throw new ArgumentException (
  288. "Unable to wrap the given object with JsonData");
  289. }
  290. public JsonData (string str)
  291. {
  292. type = JsonType.String;
  293. inst_string = str;
  294. }
  295. #endregion
  296. #region Implicit Conversions
  297. public static implicit operator JsonData (Boolean data)
  298. {
  299. return new JsonData (data);
  300. }
  301. public static implicit operator JsonData (Double data)
  302. {
  303. return new JsonData (data);
  304. }
  305. public static implicit operator JsonData (Int32 data)
  306. {
  307. return new JsonData (data);
  308. }
  309. public static implicit operator JsonData (Int64 data)
  310. {
  311. return new JsonData (data);
  312. }
  313. public static implicit operator JsonData (String data)
  314. {
  315. return new JsonData (data);
  316. }
  317. #endregion
  318. #region Explicit Conversions
  319. public static explicit operator Boolean (JsonData data)
  320. {
  321. if (data.type != JsonType.Boolean)
  322. throw new InvalidCastException (
  323. "Instance of JsonData doesn't hold a double");
  324. return data.inst_boolean;
  325. }
  326. public static explicit operator Double (JsonData data)
  327. {
  328. if (data.type != JsonType.Double)
  329. throw new InvalidCastException (
  330. "Instance of JsonData doesn't hold a double");
  331. return data.inst_double;
  332. }
  333. public static explicit operator Int32 (JsonData data)
  334. {
  335. if (data.type != JsonType.Int)
  336. throw new InvalidCastException (
  337. "Instance of JsonData doesn't hold an int");
  338. return data.inst_int;
  339. }
  340. public static explicit operator Int64 (JsonData data)
  341. {
  342. if (data.type != JsonType.Long)
  343. throw new InvalidCastException (
  344. "Instance of JsonData doesn't hold an int");
  345. return data.inst_long;
  346. }
  347. public static explicit operator String (JsonData data)
  348. {
  349. if (data.type != JsonType.String)
  350. throw new InvalidCastException (
  351. "Instance of JsonData doesn't hold a string");
  352. return data.inst_string;
  353. }
  354. #endregion
  355. #region ICollection Methods
  356. void ICollection.CopyTo (Array array, int index)
  357. {
  358. EnsureCollection ().CopyTo (array, index);
  359. }
  360. #endregion
  361. #region IDictionary Methods
  362. void IDictionary.Add (object key, object value)
  363. {
  364. JsonData data = ToJsonData (value);
  365. EnsureDictionary ().Add (key, data);
  366. KeyValuePair<string, JsonData> entity =
  367. new KeyValuePair<string, JsonData> ((string) key, data);
  368. object_list.Add (entity);
  369. json = null;
  370. }
  371. void IDictionary.Clear ()
  372. {
  373. EnsureDictionary ().Clear ();
  374. object_list.Clear ();
  375. json = null;
  376. }
  377. bool IDictionary.Contains (object key)
  378. {
  379. return EnsureDictionary ().Contains (key);
  380. }
  381. IDictionaryEnumerator IDictionary.GetEnumerator ()
  382. {
  383. return ((IOrderedDictionary) this).GetEnumerator ();
  384. }
  385. void IDictionary.Remove (object key)
  386. {
  387. EnsureDictionary ().Remove (key);
  388. for (int i = 0; i < object_list.Count; i++) {
  389. if (object_list[i].Key == (string) key) {
  390. object_list.RemoveAt (i);
  391. break;
  392. }
  393. }
  394. json = null;
  395. }
  396. #endregion
  397. #region IEnumerable Methods
  398. IEnumerator IEnumerable.GetEnumerator ()
  399. {
  400. return EnsureCollection ().GetEnumerator ();
  401. }
  402. #endregion
  403. #region IJsonWrapper Methods
  404. bool IJsonWrapper.GetBoolean ()
  405. {
  406. if (type != JsonType.Boolean)
  407. throw new InvalidOperationException (
  408. "JsonData instance doesn't hold a boolean");
  409. return inst_boolean;
  410. }
  411. double IJsonWrapper.GetDouble ()
  412. {
  413. if (type != JsonType.Double)
  414. throw new InvalidOperationException (
  415. "JsonData instance doesn't hold a double");
  416. return inst_double;
  417. }
  418. int IJsonWrapper.GetInt ()
  419. {
  420. if (type != JsonType.Int)
  421. throw new InvalidOperationException (
  422. "JsonData instance doesn't hold an int");
  423. return inst_int;
  424. }
  425. long IJsonWrapper.GetLong ()
  426. {
  427. if (type != JsonType.Long)
  428. throw new InvalidOperationException (
  429. "JsonData instance doesn't hold a long");
  430. return inst_long;
  431. }
  432. string IJsonWrapper.GetString ()
  433. {
  434. if (type != JsonType.String)
  435. throw new InvalidOperationException (
  436. "JsonData instance doesn't hold a string");
  437. return inst_string;
  438. }
  439. void IJsonWrapper.SetBoolean (bool val)
  440. {
  441. type = JsonType.Boolean;
  442. inst_boolean = val;
  443. json = null;
  444. }
  445. void IJsonWrapper.SetDouble (double val)
  446. {
  447. type = JsonType.Double;
  448. inst_double = val;
  449. json = null;
  450. }
  451. void IJsonWrapper.SetInt (int val)
  452. {
  453. type = JsonType.Int;
  454. inst_int = val;
  455. json = null;
  456. }
  457. void IJsonWrapper.SetLong (long val)
  458. {
  459. type = JsonType.Long;
  460. inst_long = val;
  461. json = null;
  462. }
  463. void IJsonWrapper.SetString (string val)
  464. {
  465. type = JsonType.String;
  466. inst_string = val;
  467. json = null;
  468. }
  469. string IJsonWrapper.ToJson ()
  470. {
  471. return ToJson ();
  472. }
  473. void IJsonWrapper.ToJson (JsonWriter writer)
  474. {
  475. ToJson (writer);
  476. }
  477. #endregion
  478. #region IList Methods
  479. int IList.Add (object value)
  480. {
  481. return Add (value);
  482. }
  483. void IList.Clear ()
  484. {
  485. EnsureList ().Clear ();
  486. json = null;
  487. }
  488. bool IList.Contains (object value)
  489. {
  490. return EnsureList ().Contains (value);
  491. }
  492. int IList.IndexOf (object value)
  493. {
  494. return EnsureList ().IndexOf (value);
  495. }
  496. void IList.Insert (int index, object value)
  497. {
  498. EnsureList ().Insert (index, value);
  499. json = null;
  500. }
  501. void IList.Remove (object value)
  502. {
  503. EnsureList ().Remove (value);
  504. json = null;
  505. }
  506. void IList.RemoveAt (int index)
  507. {
  508. EnsureList ().RemoveAt (index);
  509. json = null;
  510. }
  511. #endregion
  512. #region IOrderedDictionary Methods
  513. IDictionaryEnumerator IOrderedDictionary.GetEnumerator ()
  514. {
  515. EnsureDictionary ();
  516. return new OrderedDictionaryEnumerator (
  517. object_list.GetEnumerator ());
  518. }
  519. void IOrderedDictionary.Insert (int idx, object key, object value)
  520. {
  521. string property = (string) key;
  522. JsonData data = ToJsonData (value);
  523. this[property] = data;
  524. KeyValuePair<string, JsonData> entity =
  525. new KeyValuePair<string, JsonData> (property, data);
  526. object_list.Insert (idx, entity);
  527. }
  528. void IOrderedDictionary.RemoveAt (int idx)
  529. {
  530. EnsureDictionary ();
  531. inst_object.Remove (object_list[idx].Key);
  532. object_list.RemoveAt (idx);
  533. }
  534. #endregion
  535. #region Private Methods
  536. private ICollection EnsureCollection ()
  537. {
  538. if (type == JsonType.Array)
  539. return (ICollection) inst_array;
  540. if (type == JsonType.Object)
  541. return (ICollection) inst_object;
  542. throw new InvalidOperationException (
  543. "The JsonData instance has to be initialized first");
  544. }
  545. private IDictionary EnsureDictionary ()
  546. {
  547. if (type == JsonType.Object)
  548. return (IDictionary) inst_object;
  549. if (type != JsonType.None)
  550. throw new InvalidOperationException (
  551. "Instance of JsonData is not a dictionary");
  552. type = JsonType.Object;
  553. inst_object = new Dictionary<string, JsonData> ();
  554. object_list = new List<KeyValuePair<string, JsonData>> ();
  555. return (IDictionary) inst_object;
  556. }
  557. private IList EnsureList ()
  558. {
  559. if (type == JsonType.Array)
  560. return (IList) inst_array;
  561. if (type != JsonType.None)
  562. throw new InvalidOperationException (
  563. "Instance of JsonData is not a list");
  564. type = JsonType.Array;
  565. inst_array = new List<JsonData> ();
  566. return (IList) inst_array;
  567. }
  568. private JsonData ToJsonData (object obj)
  569. {
  570. if (obj == null)
  571. return null;
  572. if (obj is JsonData)
  573. return (JsonData) obj;
  574. return new JsonData (obj);
  575. }
  576. private static void WriteJson (IJsonWrapper obj, JsonWriter writer)
  577. {
  578. if (obj == null) {
  579. writer.Write (null);
  580. return;
  581. }
  582. if (obj.IsString) {
  583. writer.Write (obj.GetString ());
  584. return;
  585. }
  586. if (obj.IsBoolean) {
  587. writer.Write (obj.GetBoolean ());
  588. return;
  589. }
  590. if (obj.IsDouble) {
  591. writer.Write (obj.GetDouble ());
  592. return;
  593. }
  594. if (obj.IsInt) {
  595. writer.Write (obj.GetInt ());
  596. return;
  597. }
  598. if (obj.IsLong) {
  599. writer.Write (obj.GetLong ());
  600. return;
  601. }
  602. if (obj.IsArray) {
  603. writer.WriteArrayStart ();
  604. foreach (object elem in (IList) obj)
  605. WriteJson ((JsonData) elem, writer);
  606. writer.WriteArrayEnd ();
  607. return;
  608. }
  609. if (obj.IsObject) {
  610. writer.WriteObjectStart ();
  611. foreach (DictionaryEntry entity in ((IDictionary)obj))
  612. {
  613. writer.WritePropertyName ((string) entity.Key);
  614. WriteJson ((JsonData) entity.Value, writer);
  615. }
  616. writer.WriteObjectEnd ();
  617. return;
  618. }
  619. }
  620. #endregion
  621. public int Add (object value)
  622. {
  623. JsonData data = ToJsonData (value);
  624. json = null;
  625. return EnsureList ().Add (data);
  626. }
  627. public void Clear ()
  628. {
  629. if (IsObject) {
  630. ((IDictionary) this).Clear ();
  631. return;
  632. }
  633. if (IsArray) {
  634. ((IList) this).Clear ();
  635. return;
  636. }
  637. }
  638. public bool Equals (JsonData x)
  639. {
  640. if (x == null)
  641. return false;
  642. if (x.type != this.type)
  643. return false;
  644. switch (this.type) {
  645. case JsonType.None:
  646. return true;
  647. case JsonType.Object:
  648. return this.inst_object.Equals (x.inst_object);
  649. case JsonType.Array:
  650. return this.inst_array.Equals (x.inst_array);
  651. case JsonType.String:
  652. return this.inst_string.Equals (x.inst_string);
  653. case JsonType.Int:
  654. return this.inst_int.Equals (x.inst_int);
  655. case JsonType.Long:
  656. return this.inst_long.Equals (x.inst_long);
  657. case JsonType.Double:
  658. return this.inst_double.Equals (x.inst_double);
  659. case JsonType.Boolean:
  660. return this.inst_boolean.Equals (x.inst_boolean);
  661. }
  662. return false;
  663. }
  664. public JsonType GetJsonType ()
  665. {
  666. return type;
  667. }
  668. public void SetJsonType (JsonType type)
  669. {
  670. if (this.type == type)
  671. return;
  672. switch (type) {
  673. case JsonType.None:
  674. break;
  675. case JsonType.Object:
  676. inst_object = new Dictionary<string, JsonData> ();
  677. object_list = new List<KeyValuePair<string, JsonData>> ();
  678. break;
  679. case JsonType.Array:
  680. inst_array = new List<JsonData> ();
  681. break;
  682. case JsonType.String:
  683. inst_string = default (String);
  684. break;
  685. case JsonType.Int:
  686. inst_int = default (Int32);
  687. break;
  688. case JsonType.Long:
  689. inst_long = default (Int64);
  690. break;
  691. case JsonType.Double:
  692. inst_double = default (Double);
  693. break;
  694. case JsonType.Boolean:
  695. inst_boolean = default (Boolean);
  696. break;
  697. }
  698. this.type = type;
  699. }
  700. public string ToJson ()
  701. {
  702. if (json != null)
  703. return json;
  704. StringWriter sw = new StringWriter ();
  705. JsonWriter writer = new JsonWriter (sw);
  706. writer.Validate = false;
  707. WriteJson (this, writer);
  708. json = sw.ToString ();
  709. return json;
  710. }
  711. public void ToJson (JsonWriter writer)
  712. {
  713. bool old_validate = writer.Validate;
  714. writer.Validate = false;
  715. WriteJson (this, writer);
  716. writer.Validate = old_validate;
  717. }
  718. public override string ToString ()
  719. {
  720. switch (type) {
  721. case JsonType.Array:
  722. return "JsonData array";
  723. case JsonType.Boolean:
  724. return inst_boolean.ToString ();
  725. case JsonType.Double:
  726. return inst_double.ToString ();
  727. case JsonType.Int:
  728. return inst_int.ToString ();
  729. case JsonType.Long:
  730. return inst_long.ToString ();
  731. case JsonType.Object:
  732. return "JsonData object";
  733. case JsonType.String:
  734. return inst_string;
  735. }
  736. return "Uninitialized JsonData";
  737. }
  738. }
  739. internal class OrderedDictionaryEnumerator : IDictionaryEnumerator
  740. {
  741. IEnumerator<KeyValuePair<string, JsonData>> list_enumerator;
  742. public object Current {
  743. get { return Entry; }
  744. }
  745. public DictionaryEntry Entry
  746. {
  747. get {
  748. KeyValuePair<string, JsonData> curr = list_enumerator.Current;
  749. return new DictionaryEntry(curr.Key, curr.Value);
  750. }
  751. }
  752. public object Key {
  753. get { return list_enumerator.Current.Key; }
  754. }
  755. public object Value {
  756. get { return list_enumerator.Current.Value; }
  757. }
  758. public OrderedDictionaryEnumerator (
  759. IEnumerator<KeyValuePair<string, JsonData>> enumerator)
  760. {
  761. list_enumerator = enumerator;
  762. }
  763. public bool MoveNext ()
  764. {
  765. return list_enumerator.MoveNext ();
  766. }
  767. public void Reset ()
  768. {
  769. list_enumerator.Reset ();
  770. }
  771. }
  772. }