Skip to content

Commit

Permalink
fix: possible issue where device not removed from the list when renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Apr 1, 2024
1 parent 9aac99e commit 8ed0f14
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void Add(T item)
throw new ArgumentNullException();
}

_byId.TryAdd(item.Id, item);
_byName.TryAdd(GetNameKey(item), item);
_byId[item.Id] = item;
_byName[GetNameKey(item)] = item;
}

public void Clear()
Expand Down Expand Up @@ -82,7 +82,7 @@ public bool Remove(T item)
throw new ArgumentNullException();
}

var removeId = _byId.Remove(item.Id);
var removeId = _byId.Remove(item.Id, out var removedById);
var removeName = _byName.Remove(GetNameKey(item), out var removedByName);

//If we found it by name, remove it also with it's id
Expand All @@ -93,6 +93,12 @@ public bool Remove(T item)
_byId.Remove(removedByName.Id);
}

//Same thing if we removed it by ID, try to remove from the name in case the name had changed
if (removeId)
{
_byName.Remove(GetNameKey(removedById));
}

return removeId || removeName;
}

Expand Down

0 comments on commit 8ed0f14

Please sign in to comment.