Beispiel #1
0
 public override void Assign(ConfigItem other)
 {
     if (other is SingleItem <T> otherItem)
     {
         var args = new UpdatedArgs {
             OldValue = value, NewValue = otherItem.value
         };
         value = otherItem.value;
         Updated?.Invoke(this, args);
     }
     else
     {
         throw new InvalidTypeAssignmentException(this, other);
     }
 }
Beispiel #2
0
        public override void Assign(ConfigItem other)
        {
            if (other is ItemList <T> otherList)
            {
                var newList = new List <T>();
                var added   = new List <T>();

                foreach (var r in otherList.list)
                {
                    int io = list.FindIndex(r.Equals);
                    if (io == -1)
                    {
                        newList.Add(r);
                        added.Add(r);
                    }
                    else
                    {
                        newList.Add(list[io]);
                        list.RemoveAt(io);
                    }
                }

                list.ForEach(i => ItemDeleted?.Invoke(this, new ItemDeletedArgs {
                    OldItem = i
                }));
                added.ForEach(i => ItemAdded?.Invoke(this, new ItemAddedArgs {
                    NewItem = i
                }));
                var updatedArgs = new UpdatedArgs {
                    DeletedItems = list, AddedItems = added, NewList = newList
                };
                list = newList;
                Updated?.Invoke(this, updatedArgs);
            }
            else
            {
                throw new InvalidTypeAssignmentException(this, other);
            }
        }
Beispiel #3
0
 private void OnUpdated(UpdatedArgs e)
 {
     Updated?.Invoke(this, e);
 }