Guest User

Untitled

a guest
May 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. class SomePoco
  2. {
  3. public int Id{get;set;}
  4. public string Name{get;set;}
  5. }
  6.  
  7. var p=new SomePoco{Id=4,Name="spender"};
  8. var json=JsonConvert.SerializeObject(p);
  9. var pr = JsonConvert.DeserializeObject<SomePoco>(json);
  10. Console.WriteLine($"Id:{pr.Id}, Name:{pr.Name}");
  11.  
  12. class SomeImmutablePoco
  13. {
  14. public SomeImmutablePoco(int id, string name)
  15. {
  16. Id = id;
  17. Name = name;
  18. }
  19. public int Id{get;}
  20. public string Name{get;}
  21. }
  22.  
  23. var p = new SomeImmutablePoco(5, "spender's immutable friend");
  24. var json = JsonConvert.SerializeObject(p);
  25. var pr = JsonConvert.DeserializeObject<SomeImmutablePoco>(json);
  26. Console.WriteLine($"Id:{pr.Id}, Name:{pr.Name}");
  27.  
  28. class SomeImmutablePoco
  29. {
  30. public SomeImmutablePoco(int pocoId, string name)
  31. {
  32. Id = pocoId;
  33. Name = name;
  34. }
  35. public int Id{get;}
  36. public string Name{get;}
  37. }
  38.  
  39. var p = new SomeImmutablePoco(666, "diabolo");
  40. var json = JsonConvert.SerializeObject(p);
  41. var pr = JsonConvert.DeserializeObject<SomeImmutablePoco>(json);
  42. Console.WriteLine($"Id:{pr.Id}, Name:{pr.Name}");
  43.  
  44. class SomeImmutablePoco
  45. {
  46. public SomeImmutablePoco(int pocoId, string name)
  47. {
  48.  
  49.  
  50. Id = pocoId;
  51. Name = name;
  52. }
  53.  
  54. [JsonProperty("pocoId")]
  55. public int Id { get; }
  56. public string Name { get; }
  57. }
Add Comment
Please, Sign In to add comment