Created
November 3, 2012 00:23
-
-
Save Buildstarted/4005222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SafeCollection<T> : ICollection<T> | |
| { | |
| private readonly ConcurrentDictionary<T, bool> _inner = new ConcurrentDictionary<T, bool>(); | |
| public void Add(T item) | |
| { | |
| _inner.TryAdd(item, true); | |
| } | |
| public void Clear() | |
| { | |
| _inner.Clear(); | |
| } | |
| public bool Contains(T item) | |
| { | |
| return _inner.ContainsKey(item); | |
| } | |
| public void CopyTo(T[] array, int arrayIndex) | |
| { | |
| _inner.Keys.CopyTo(array, arrayIndex); | |
| } | |
| public int Count | |
| { | |
| get | |
| { | |
| return _inner.Count; | |
| } | |
| } | |
| public bool IsReadOnly | |
| { | |
| get { return false; } | |
| } | |
| public bool Remove(T item) | |
| { | |
| bool value; | |
| return _inner.TryRemove(item, out value); | |
| } | |
| public IEnumerator<T> GetEnumerator() | |
| { | |
| return _inner.Keys.GetEnumerator(); | |
| } | |
| IEnumerator IEnumerable.GetEnumerator() | |
| { | |
| return GetEnumerator(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment