Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DataContract(IsReference=true)]
- public abstract class IDable<T> {
- [DataMember]
- public T ID { get; set; }
- }
- [DataContract(IsReference=true)]
- [KnownType(typeof(DescriptiveObservation))]
- [KnownType(typeof(NoteObservation))]
- [KnownType(typeof(NumericObservation))]
- [KnownType(typeof(ScoredObservation))]
- public class ObservationGroup : IDable<int> {
- [DataMember]
- public string Title { get; set; }
- [DataMember]
- public List<Observation> Observations { get; set; }
- [OnDeserializing]
- void OnDeserializing(StreamingContext context)
- {
- init();
- }
- public ObservationGroup() {
- init();
- }
- private void init()
- {
- Observations = new List<Observation>();
- ObservationRecords = new List<ObservationRecord>();
- }
- }
- [DataContract(IsReference = true)]
- public class DescriptiveObservation : Observation
- {
- protected override ObservationType GetObservationType()
- {
- return ObservationType.Descriptive;
- }
- }
- [DataContract(IsReference = true)]
- public class NoteObservation : Observation
- {
- protected override ObservationType GetObservationType()
- {
- return ObservationType.Note;
- }
- }
- [DataContract(IsReference = true)]
- public class NumericObservation : Observation
- {
- [DataMember]
- public double ConstraintMaximum { get; set; }
- [DataMember]
- public double ConstraintMinimum { get; set; }
- [DataMember]
- public int PrecisionMaximum { get; set; }
- [DataMember]
- public int PrecisionMinimum { get; set; }
- [DataMember]
- public string UnitType { get; set; }
- protected override ObservationType GetObservationType()
- {
- return ObservationType.Numeric;
- }
- }
- [DataContract(IsReference = true)]
- public class ScoredObservation : Observation {
- [DataMember]
- public int Value { get; set; }
- protected override ObservationType GetObservationType() {
- return ObservationType.Scored;
- }
- }
- var settings = new Newtonsoft.Json.JsonSerializerSettings();
- settings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects;
- Newtonsoft.Json.JsonConvert.SerializeObject(AnInitializedScoresheet, Newtonsoft.Json.Formatting.None, settings);
- return Newtonsoft.Json.JsonConvert.DeserializeObject(returnedStringFromClient, typeof(Scoresheet));
- //Scoresheet contains a list of observationgroups
- JsonConvert.DeserializeObject(returnedStringFromClient, typeof(Scoresheet), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
Add Comment
Please, Sign In to add comment