コード例 #1
0
        public override void WriteJson(JsonWriter writer, object value,
                                       JsonSerializer serializer)
        {
            if (value == null)
            {
                return;
            }
            var test = (Models.Test)value;

            var obj = new TestSchema
            {
                Collection = test.ToList(),
                Title      = test.Title,
                Subject    = test.Subject,
                TimeLimit  = test.TimeLimit,
                Mode       = test.Mode,
                Id         = test.Id
            };

            serializer.Serialize(writer, obj);
        }
コード例 #2
0
        public override object ReadJson(
            JsonReader reader, Type objectType,
            object existingValue, JsonSerializer serializer)
        {
            if (reader == null)
            {
                return(null);
            }
            TestSchema             obj       = serializer.Deserialize <TestSchema>(reader);
            List <Models.Question> questions = obj.Collection;

            Models.Test test = new Models.Test {
                Title     = obj.Title,
                Subject   = obj.Subject,
                TimeLimit = obj.TimeLimit,
                Mode      = obj.Mode,
                Id        = obj.Id
            };
            foreach (Models.Question q in questions)
            {
                test.Add(q);
            }
            return(test);
        }