示例#1
0
        /// <summary>
        /// Reads the JSON representation of an <see cref="EntityCollection{T}"/> instance.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="existingValue">The existing value of the object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            var collection = (EntityCollection)Activator.CreateInstance(objectType);

            if (reader.CanReadArray())
            {
                while (reader.Read() && reader.TokenType != JsonToken.EndArray)
                {
                    collection.Add((Entity)StateObjectConverter.Default.ReadJson(reader, collection.EntityType, null, serializer));
                }
            }

            return(collection);
        }
示例#2
0
 /// <summary>
 /// Reads the JSON representation of an <see cref="EventCollection"/> instance.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
 /// <param name="objectType">The type of object.</param>
 /// <param name="existingValue">The existing value of the object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
 {
     return(reader.CanReadArray() ? new EventCollection(serializer.Deserialize <List <Event> >(reader)) : null);
 }