File tree 1 file changed +9
-3
lines changed
SoundSwitch.Common/Framework/Audio/Collection
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ public void Add(T item)
50
50
throw new ArgumentNullException ( ) ;
51
51
}
52
52
53
- _byId . TryAdd ( item . Id , item ) ;
54
- _byName . TryAdd ( GetNameKey ( item ) , item ) ;
53
+ _byId [ item . Id ] = item ;
54
+ _byName [ GetNameKey ( item ) ] = item ;
55
55
}
56
56
57
57
public void Clear ( )
@@ -82,7 +82,7 @@ public bool Remove(T item)
82
82
throw new ArgumentNullException ( ) ;
83
83
}
84
84
85
- var removeId = _byId . Remove ( item . Id ) ;
85
+ var removeId = _byId . Remove ( item . Id , out var removedById ) ;
86
86
var removeName = _byName . Remove ( GetNameKey ( item ) , out var removedByName ) ;
87
87
88
88
//If we found it by name, remove it also with it's id
@@ -93,6 +93,12 @@ public bool Remove(T item)
93
93
_byId . Remove ( removedByName . Id ) ;
94
94
}
95
95
96
+ //Same thing if we removed it by ID, try to remove from the name in case the name had changed
97
+ if ( removeId )
98
+ {
99
+ _byName . Remove ( GetNameKey ( removedById ) ) ;
100
+ }
101
+
96
102
return removeId || removeName ;
97
103
}
98
104
You can’t perform that action at this time.
0 commit comments