Replacement for JDIS Importer
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

63 rindas
1.6 KiB

  1. using System.Globalization;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Converters;
  4. namespace jdis_import.RESTObjects
  5. {
  6. [JsonObject(MemberSerialization.OptIn)]
  7. public class RESTResponse<T>
  8. {
  9. #region Fields
  10. private RESTMeta _meta = null;
  11. private T _data;
  12. #endregion
  13. #region Properties
  14. [JsonProperty(PropertyName = "meta")]
  15. public RESTMeta meta
  16. {
  17. get
  18. {
  19. if (_meta == null)
  20. {
  21. _meta = new RESTMeta();
  22. }
  23. return _meta;
  24. }
  25. set { _meta = value; }
  26. }
  27. [JsonProperty(PropertyName = "data")]
  28. public T data
  29. {
  30. get { return _data; }
  31. set { _data = value; }
  32. }
  33. #endregion
  34. }
  35. public static class Deserialize
  36. {
  37. public static T FromJson<T>(string json)
  38. {
  39. return JsonConvert.DeserializeObject<T>(json, Converter.Settings);
  40. }
  41. }
  42. public static class Serialize
  43. {
  44. public static string ToJson<T>(this T self)
  45. {
  46. return JsonConvert.SerializeObject(self, Converter.Settings);
  47. }
  48. }
  49. internal static class Converter
  50. {
  51. public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
  52. {
  53. MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
  54. DateParseHandling = DateParseHandling.None,
  55. DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
  56. };
  57. }
  58. }