Exemple #1
0
        public T this[int index]
        {
            get
            {
                var item = items[index];

                if (!item.HasValue)
                {
                    items[index] = item = item.WithValue(GetValue(item.Node));
                }

                return(item.Value);
            }
            set
            {
                var item = items[index];
                cursor.MoveTo(item.Node);
                SetValue(cursor, item.Value, ref value);

                if (advisor.OnReplacing(item.Value, value))
                {
                    // Commit the replacement
                    items[index] = item.WithValue(value);
                    advisor.OnReplaced(item.Value, value, index);
                }
                else
                {
                    // Rollback the replacement
                    var oldValue = item.Value;
                    SetValue(cursor, value, ref oldValue);
                    items[index] = item.WithValue(oldValue);
                }
            }
        }
Exemple #2
0
        private void SetValueAt(int index, T value)
        {
            var item = items[index];

            cursor.MoveTo(item.Node);
            SetValue(cursor, item.Value, ref value);

            if (ShouldReplace(item.Value, value))
            {
                items[index] = item.WithValue(value);
                DetachPropertyChanged(item.Value);
                AttachPropertyChanged(value);
                NotifyListChanged(ListChangedType.ItemChanged, index);
            }
            else
            {
                var oldValue = item.Value;
                SetValue(cursor, value, ref oldValue);
                items[index] = item.WithValue(oldValue);
            }
        }