Пример #1
0
 /// <summary>
 /// Pads the generic IList.
 /// </summary>
 /// <param name="list">The list.</param>
 /// <param name="property">The property.</param>
 /// <param name="toIndex">To index.</param>
 private void PadGenericIList(object list, ControllerProperty property, int toIndex)
 {
     while (property.GenericIListCount(list) < toIndex)
     {
         property.GenericIListAdd(list, GetDefaultValue(property.GenericIListType));
     }
 }
Пример #2
0
        /// <summary>
        /// Sets the generic IList changes.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="property">The property.</param>
        /// <param name="changes">The changes.</param>
        /// <param name="sync">if set to <c>true</c> synchronize changes.</param>
        private void SetGenericIListChanges(object list, ControllerProperty property, ObservableCollectionChanges changes, bool sync)
        {
            try
            {
                SyncChanges = sync;
                foreach (var change in changes.Actions)
                {
                    if (change.Action == ObservableCollectionChangeAction.Add)
                    {
                        var startIndex = change.NewStartingIndex.Value;

                        foreach (var item in change.NewItems)
                        {
                            PadGenericIList(list, property, startIndex);

                            if (startIndex >= property.GenericIListCount(list))
                            {
                                property.GenericIListAdd(list, item.ToObject(property.GenericIListType));
                            }
                            else
                            {
                                property.GenericIListInsert(list, startIndex, item.ToObject(property.GenericIListType));
                            }

                            startIndex++;
                        }
                    }
                    else if (change.Action == ObservableCollectionChangeAction.Remove)
                    {
                        var removeIndex = change.OldStartingIndex.Value;

                        if (property.GenericIListCount(list) > removeIndex)
                        {
                            property.GenericIListRemoveAt(list, removeIndex);
                        }
                    }
                    else if (change.Action == ObservableCollectionChangeAction.Replace)
                    {
                        var startIndex = change.NewStartingIndex.Value;

                        foreach (var item in change.NewItems)
                        {
                            PadGenericIList(list, property, startIndex);

                            if (startIndex >= property.GenericIListCount(list))
                            {
                                property.GenericIListAdd(list, item.ToObject(property.GenericIListType));
                            }
                            else
                            {
                                property.GenericIListReplace(list, startIndex, item.ToObject(property.GenericIListType));
                            }

                            startIndex++;
                        }
                    }
                }
            }
            finally
            {
                SyncChanges = true;
            }
        }