Пример #1
0
        /// <inheritdoc/>
        public bool Load(JProperty newProperty, bool reload = false)
        {
            Covenant.Requires <ArgumentNullException>(newProperty != null);

            var changed = !NeonHelper.JTokenEquals(property, newProperty);

            property = newProperty;

            if (property.Value == null || property.Value.Type == JTokenType.Null)
            {
                listWrapper = null;
            }
            else if (property.Value.Type == JTokenType.Array)
            {
                listWrapper = new LinkListWrapper <TEntity>(parentEntity, context, (JArray)property.Value, null);
            }
            else
            {
                listWrapper = null;
            }

            if (reload && changed)
            {
                parentEntity._OnPropertyChanged(PropertyName);
            }

            return(changed);
        }
Пример #2
0
        /// <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 LinkListMapper(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;
        }
Пример #3
0
        /// <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 LinkListWrapper <TEntity>(parentEntity, context, jArray, items);
        }