/// <summary> /// Constructor. /// </summary> /// <param name="parentEntity">The <see cref="IDynamicEntity"/> that owns this mapper.</param> /// <param name="jsonName">The JSON property name.</param> /// <param name="propertyName">The entity property name.</param> /// <param name="context">The <see cref="IDynamicEntityContext"/> or <c>null</c>.</param> public ListMapper(IDynamicEntity parentEntity, string jsonName, string propertyName, IDynamicEntityContext context) { Covenant.Requires <ArgumentNullException>(parentEntity != null); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(jsonName)); Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(propertyName)); this.parentEntity = parentEntity; this.context = context; this.JsonName = jsonName; this.PropertyName = propertyName; this.property = null; this.listWrapper = null; }
/// <summary> /// Sets the collection items. /// </summary> /// <param name="items">The collection items or <c>null</c>.</param> public void Set(IEnumerable <TEntity> items) { if (items == null) { if (listWrapper != null) { listWrapper.Detach(); } property.Value = null; listWrapper = null; return; } var jArray = new JArray(); property.Value = jArray; listWrapper = new ListWrapper <TEntity>(parentEntity, jArray, items); }