Beispiel #1
0
 public bool Remove(ThingBase thing)
 {
     lock (Lock)
     {
         // This will not throw an exception if the thing is not there.
         return(_interalList.Remove(thing));
     }
 }
Beispiel #2
0
 /// <summary>
 /// Modifying the collection this method returns will have no effect on the underlying list of things.
 /// </summary>
 public ThingBase[] GetThingsArray()
 {
     lock (Lock)
     {
         var result = new ThingBase[_interalList.Count];
         _interalList.CopyTo(result);
         return(result);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Adds the thing if it's not already there.
 /// Returns null if it added the new thing or existing thing if there is something with the given id.
 /// </summary>
 public ThingBase AddIfMissing(ThingBase otherThing)
 {
     lock (Lock)
     {
         // Check if it already exists.
         ThingBase existing = _interalList.Find(t => t.Id == otherThing.Id);
         if (existing == null)
         {
             // It is not here yet - add it.
             _interalList.Add(otherThing);
             // Return null to incidate the thing was added.
             return(null);
         }
         // There is already something with this id - return it.
         return(existing);
     }
 }