JsonData.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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 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> entry in
  95. object_list) {
  96. keys.Add (entry.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> entry in
  106. object_list) {
  107. values.Add (entry.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_entry = object_list[idx];
  172. inst_object[old_entry.Key] = data;
  173. KeyValuePair<string, JsonData> entry =
  174. new KeyValuePair<string, JsonData> (old_entry.Key, data);
  175. object_list[idx] = entry;
  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> entry =
  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] = entry;
  205. break;
  206. }
  207. }
  208. } else
  209. object_list.Add (entry);
  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> entry = object_list[index];
  227. KeyValuePair<string, JsonData> new_entry =
  228. new KeyValuePair<string, JsonData> (entry.Key, value);
  229. object_list[index] = new_entry;
  230. inst_object[entry.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> entry =
  367. new KeyValuePair<string, JsonData> ((string) key, data);
  368. object_list.Add (entry);
  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> entry =
  525. new KeyValuePair<string, JsonData> (property, data);
  526. object_list.Insert (idx, entry);
  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 entry in ((IDictionary) obj)) {
  612. writer.WritePropertyName ((string) entry.Key);
  613. WriteJson ((JsonData) entry.Value, writer);
  614. }
  615. writer.WriteObjectEnd ();
  616. return;
  617. }
  618. }
  619. #endregion
  620. public int Add (object value)
  621. {
  622. JsonData data = ToJsonData (value);
  623. json = null;
  624. return EnsureList ().Add (data);
  625. }
  626. public void Clear ()
  627. {
  628. if (IsObject) {
  629. ((IDictionary) this).Clear ();
  630. return;
  631. }
  632. if (IsArray) {
  633. ((IList) this).Clear ();
  634. return;
  635. }
  636. }
  637. public bool Equals (JsonData x)
  638. {
  639. if (x == null)
  640. return false;
  641. if (x.type != this.type)
  642. return false;
  643. switch (this.type) {
  644. case JsonType.None:
  645. return true;
  646. case JsonType.Object:
  647. return this.inst_object.Equals (x.inst_object);
  648. case JsonType.Array:
  649. return this.inst_array.Equals (x.inst_array);
  650. case JsonType.String:
  651. return this.inst_string.Equals (x.inst_string);
  652. case JsonType.Int:
  653. return this.inst_int.Equals (x.inst_int);
  654. case JsonType.Long:
  655. return this.inst_long.Equals (x.inst_long);
  656. case JsonType.Double:
  657. return this.inst_double.Equals (x.inst_double);
  658. case JsonType.Boolean:
  659. return this.inst_boolean.Equals (x.inst_boolean);
  660. }
  661. return false;
  662. }
  663. public JsonType GetJsonType ()
  664. {
  665. return type;
  666. }
  667. public void SetJsonType (JsonType type)
  668. {
  669. if (this.type == type)
  670. return;
  671. switch (type) {
  672. case JsonType.None:
  673. break;
  674. case JsonType.Object:
  675. inst_object = new Dictionary<string, JsonData> ();
  676. object_list = new List<KeyValuePair<string, JsonData>> ();
  677. break;
  678. case JsonType.Array:
  679. inst_array = new List<JsonData> ();
  680. break;
  681. case JsonType.String:
  682. inst_string = default (String);
  683. break;
  684. case JsonType.Int:
  685. inst_int = default (Int32);
  686. break;
  687. case JsonType.Long:
  688. inst_long = default (Int64);
  689. break;
  690. case JsonType.Double:
  691. inst_double = default (Double);
  692. break;
  693. case JsonType.Boolean:
  694. inst_boolean = default (Boolean);
  695. break;
  696. }
  697. this.type = type;
  698. }
  699. public string ToJson ()
  700. {
  701. if (json != null)
  702. return json;
  703. StringWriter sw = new StringWriter ();
  704. JsonWriter writer = new JsonWriter (sw);
  705. writer.Validate = false;
  706. WriteJson (this, writer);
  707. json = sw.ToString ();
  708. return json;
  709. }
  710. public void ToJson (JsonWriter writer)
  711. {
  712. bool old_validate = writer.Validate;
  713. writer.Validate = false;
  714. WriteJson (this, writer);
  715. writer.Validate = old_validate;
  716. }
  717. public override string ToString ()
  718. {
  719. switch (type) {
  720. case JsonType.Array:
  721. return "JsonData array";
  722. case JsonType.Boolean:
  723. return inst_boolean.ToString ();
  724. case JsonType.Double:
  725. return inst_double.ToString ();
  726. case JsonType.Int:
  727. return inst_int.ToString ();
  728. case JsonType.Long:
  729. return inst_long.ToString ();
  730. case JsonType.Object:
  731. return "JsonData object";
  732. case JsonType.String:
  733. return inst_string;
  734. }
  735. return "Uninitialized JsonData";
  736. }
  737. }
  738. internal class OrderedDictionaryEnumerator : IDictionaryEnumerator
  739. {
  740. IEnumerator<KeyValuePair<string, JsonData>> list_enumerator;
  741. public object Current {
  742. get { return Entry; }
  743. }
  744. public DictionaryEntry Entry {
  745. get {
  746. KeyValuePair<string, JsonData> curr = list_enumerator.Current;
  747. return new DictionaryEntry (curr.Key, curr.Value);
  748. }
  749. }
  750. public object Key {
  751. get { return list_enumerator.Current.Key; }
  752. }
  753. public object Value {
  754. get { return list_enumerator.Current.Value; }
  755. }
  756. public OrderedDictionaryEnumerator (
  757. IEnumerator<KeyValuePair<string, JsonData>> enumerator)
  758. {
  759. list_enumerator = enumerator;
  760. }
  761. public bool MoveNext ()
  762. {
  763. return list_enumerator.MoveNext ();
  764. }
  765. public void Reset ()
  766. {
  767. list_enumerator.Reset ();
  768. }
  769. }
  770. }