private void Synchronize(NotifyCollectionChangedEventArgs e) { if (this.isUpdating || this.unit == null) { return; } var args = e.As <CustomConversionVm>(); switch (args.Action) { case NotifyCollectionChangedAction.Add: this.unit.CustomConversions.Add((CustomConversion)args.NewItems.Single().Conversion); break; case NotifyCollectionChangedAction.Remove: this.unit.CustomConversions.Remove((CustomConversion)args.OldItems.Single().Conversion); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: throw new NotImplementedException(); case NotifyCollectionChangedAction.Reset: // NOP break; default: throw new ArgumentOutOfRangeException(); } }
private void Synchronize(NotifyCollectionChangedEventArgs e) { if (this.isUpdating || this.unit is null) { return; } var args = e.As <FactorConversionVm>(); switch (args.Action) { case NotifyCollectionChangedAction.Add: this.unit.FactorConversions.Add((FactorConversion)args.NewItems.Single().Conversion); break; case NotifyCollectionChangedAction.Remove: this.unit.FactorConversions.Remove((FactorConversion)args.OldItems.Single().Conversion); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: throw new NotSupportedException(); case NotifyCollectionChangedAction.Reset: // NOP break; default: throw new ArgumentOutOfRangeException(nameof(e), e.Action, "Not handling"); } }
private void OnBaseUnitsChanged(NotifyCollectionChangedEventArgs args) { var typedArgs = args.As <BaseUnitViewModel>(); switch (typedArgs.Action) { case NotifyCollectionChangedAction.Add: // NOP break; case NotifyCollectionChangedAction.Remove: this.settings.BaseUnits.Remove(typedArgs.OldItems.Single().Unit); break; case NotifyCollectionChangedAction.Replace: break; case NotifyCollectionChangedAction.Move: break; case NotifyCollectionChangedAction.Reset: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException(); } }
private void Synchronize(NotifyCollectionChangedEventArgs e) { if (this.isUpdating || this.unit is null) { return; } var args = e.As <CustomConversionVm>(); switch (args.Action) { case NotifyCollectionChangedAction.Add: this.unit.CustomConversions.Add((CustomConversion)args.NewItems.Single().Conversion); break; case NotifyCollectionChangedAction.Remove: this.unit.CustomConversions.Remove((CustomConversion)args.OldItems.Single().Conversion); break; case NotifyCollectionChangedAction.Reset: // NOP break; default: throw new InvalidEnumArgumentException(nameof(args.Action), (int)args.Action, typeof(NotifyCollectionChangedAction)); } }
public void Add() { var expected = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, 1, 0); var actual = expected.As <int>(); Assert.AreEqual(expected.Action, actual.Action); Assert.AreEqual(expected.NewStartingIndex, actual.NewStartingIndex); CollectionAssert.AreEqual(expected.NewItems, actual.NewItems); Assert.AreEqual(expected.OldStartingIndex, actual.OldStartingIndex); CollectionAssert.AreEqual(new int[0], actual.OldItems); }
public void Remove() { var expected = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, 1, 0); var actual = expected.As <int>(); Assert.AreEqual(expected.Action, actual.Action); Assert.AreEqual(expected.NewStartingIndex, actual.NewStartingIndex); CollectionAssert.AreEqual(Array.Empty <int>(), actual.NewItems); Assert.AreEqual(expected.OldStartingIndex, actual.OldStartingIndex); CollectionAssert.AreEqual(expected.OldItems, actual.OldItems); }