Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. [DataContract(IsReference=true)]
  2. public abstract class IDable<T> {
  3.  
  4. [DataMember]
  5. public T ID { get; set; }
  6. }
  7.  
  8. [DataContract(IsReference=true)]
  9. [KnownType(typeof(DescriptiveObservation))]
  10. [KnownType(typeof(NoteObservation))]
  11. [KnownType(typeof(NumericObservation))]
  12. [KnownType(typeof(ScoredObservation))]
  13. public class ObservationGroup : IDable<int> {
  14.  
  15. [DataMember]
  16. public string Title { get; set; }
  17.  
  18. [DataMember]
  19. public List<Observation> Observations { get; set; }
  20.  
  21. [OnDeserializing]
  22. void OnDeserializing(StreamingContext context)
  23. {
  24. init();
  25. }
  26.  
  27. public ObservationGroup() {
  28. init();
  29. }
  30.  
  31. private void init()
  32. {
  33. Observations = new List<Observation>();
  34. ObservationRecords = new List<ObservationRecord>();
  35. }
  36.  
  37. }
  38.  
  39. [DataContract(IsReference = true)]
  40. public class DescriptiveObservation : Observation
  41. {
  42.  
  43. protected override ObservationType GetObservationType()
  44. {
  45. return ObservationType.Descriptive;
  46. }
  47. }
  48.  
  49. [DataContract(IsReference = true)]
  50. public class NoteObservation : Observation
  51. {
  52. protected override ObservationType GetObservationType()
  53. {
  54. return ObservationType.Note;
  55. }
  56. }
  57.  
  58. [DataContract(IsReference = true)]
  59. public class NumericObservation : Observation
  60. {
  61. [DataMember]
  62. public double ConstraintMaximum { get; set; }
  63. [DataMember]
  64. public double ConstraintMinimum { get; set; }
  65. [DataMember]
  66. public int PrecisionMaximum { get; set; }
  67. [DataMember]
  68. public int PrecisionMinimum { get; set; }
  69. [DataMember]
  70. public string UnitType { get; set; }
  71.  
  72. protected override ObservationType GetObservationType()
  73. {
  74. return ObservationType.Numeric;
  75. }
  76. }
  77.  
  78. [DataContract(IsReference = true)]
  79. public class ScoredObservation : Observation {
  80. [DataMember]
  81. public int Value { get; set; }
  82.  
  83. protected override ObservationType GetObservationType() {
  84. return ObservationType.Scored;
  85. }
  86. }
  87.  
  88. var settings = new Newtonsoft.Json.JsonSerializerSettings();
  89. settings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects;
  90.  
  91. Newtonsoft.Json.JsonConvert.SerializeObject(AnInitializedScoresheet, Newtonsoft.Json.Formatting.None, settings);
  92.  
  93. return Newtonsoft.Json.JsonConvert.DeserializeObject(returnedStringFromClient, typeof(Scoresheet));
  94. //Scoresheet contains a list of observationgroups
  95.  
  96. JsonConvert.DeserializeObject(returnedStringFromClient, typeof(Scoresheet), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
Add Comment
Please, Sign In to add comment