IJsonReader.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // JsonKit v0.5 - A simple but flexible Json library in a single .cs file.
  2. //
  3. // Copyright (C) 2014 Topten Software (contact@toptensoftware.com) All rights reserved.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this product
  6. // except in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the
  11. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. // either express or implied. See the License for the specific language governing permissions
  13. // and limitations under the License.
  14. using System;
  15. using System.Reflection;
  16. namespace Topten.JsonKit
  17. {
  18. /// <summary>
  19. /// Provides a reader for JSON data
  20. /// </summary>
  21. [Obfuscation(Exclude=true, ApplyToMembers=true)]
  22. public interface IJsonReader
  23. {
  24. /// <summary>
  25. /// Parses an object of specified type from the JSON stream
  26. /// </summary>
  27. /// <param name="type">The type to be parsed</param>
  28. /// <returns>A reference to the loaded instance</returns>
  29. object Parse(Type type);
  30. /// <summary>
  31. /// Parses an object of specified type from the JSON stream
  32. /// </summary>
  33. /// <typeparam name="T">The type to be parsed</typeparam>
  34. /// <returns>A reference to the loaded instance</returns>
  35. T Parse<T>();
  36. /// <summary>
  37. /// Parses from a JSON stream into an existing object instance
  38. /// </summary>
  39. /// <param name="into">The target object</param>
  40. void ParseInto(object into);
  41. /// <summary>
  42. /// The current token in the input JSON stream
  43. /// </summary>
  44. Token CurrentToken { get; }
  45. /// <summary>
  46. /// Reads a literal value from the JSON stream
  47. /// </summary>
  48. /// <param name="converter">A converter function to convert the value</param>
  49. /// <returns>The parsed and converted value</returns>
  50. object ReadLiteral(Func<object, object> converter);
  51. /// <summary>
  52. /// Reads a dictinary from the input stream
  53. /// </summary>
  54. /// <param name="callback">A callback that will be invoked for each encountered dictionary key</param>
  55. void ParseDictionary(Action<string> callback);
  56. /// <summary>
  57. /// Reads an array from the input stream
  58. /// </summary>
  59. /// <param name="callback">A callback that will be invoked as each array element is encounters</param>
  60. void ParseArray(Action callback);
  61. /// <summary>
  62. /// Gets the literal kind of the current stream token
  63. /// </summary>
  64. /// <returns></returns>
  65. LiteralKind GetLiteralKind();
  66. /// <summary>
  67. /// Gets a string literal from the JSON stream
  68. /// </summary>
  69. /// <returns></returns>
  70. string GetLiteralString();
  71. /// <summary>
  72. /// Moves to the next token in the input stream
  73. /// </summary>
  74. void NextToken();
  75. }
  76. }