Guest User

Untitled

a guest
Feb 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <Query Kind="Program">
  2. <NuGetReference>Jil</NuGetReference>
  3. <Namespace>Jil</Namespace>
  4. <Namespace>System.Runtime.Serialization</Namespace>
  5. </Query>
  6.  
  7. void Main()
  8. {
  9. var objs = new List<MyBaseClass>();
  10. objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
  11. objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
  12. objs.Add(new MySubClass(new [] { "foo", "bar", 3.0f.ToString() }));
  13.  
  14. using (var output = new StringWriter())
  15. {
  16. JSON.Serialize(
  17. objs,
  18. output,
  19. Options.ISO8601IncludeInherited
  20. );
  21. output.ToString().Dump(); // this prints [{},{},{}]
  22. }
  23. }
  24.  
  25. // Define other methods and classes here
  26. public class MyBaseClass
  27. {
  28. [DataMember]
  29. string FileName { get; set; }
  30. [DataMember]
  31. string FileCreationTime { get; set; }
  32. public MyBaseClass(string[] rawRecord)
  33. {
  34. this.FileName = rawRecord[0];
  35. this.FileCreationTime = rawRecord[1];
  36. }
  37. }
  38.  
  39. public class MySubClass : MyBaseClass
  40. {
  41. [DataMember]
  42. float X;
  43. public MySubClass(string[] rawRecord) : base(rawRecord)
  44. {
  45. this.X = float.Parse(rawRecord[2]);
  46. }
  47. }
Add Comment
Please, Sign In to add comment