Skip to content

Commit 0bccf1f

Browse files
committed
Ensure that RemoveItem() enforces business logic
Previously, when deleting items directly via `Remove()`, the `RemoveItem()` wouldn't enforce business logic. This is problematic because sometimes properties either a) disallow nulls, or b) must update their internal states when values are set to null. This would be handled when calling `SetValue()` or going directly through the property, but bypassed when calling `Remove()`. This update patches that hole, and thus resolves the `Remove()` portion of #79.
1 parent 3d1ad6b commit 0bccf1f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

OnTopic/Collections/Specialized/TrackedRecordCollection{TItem,TValue,TAttribute}.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,15 @@ protected override void SetItem(int index, TItem item) {
606606
/// cref="TrackedRecord{T}"/>s are marked as <see cref="TrackedRecord{T}.IsDirty"/>.
607607
/// </remarks>
608608
protected override void RemoveItem(int index) {
609-
var trackedRecord = this[index];
610-
if (!AssociatedTopic.IsNew) {
611-
DeletedItems.Add(trackedRecord.Key);
609+
var trackedRecord = this[index] with {
610+
Value = null
611+
};
612+
if (_topicPropertyDispatcher.Enforce(trackedRecord.Key, trackedRecord)) {
613+
if (!AssociatedTopic.IsNew) {
614+
DeletedItems.Add(trackedRecord.Key);
615+
}
616+
base.RemoveItem(index);
612617
}
613-
base.RemoveItem(index);
614618
}
615619

616620
/*==========================================================================================================================

0 commit comments

Comments
 (0)