moel@165: /* moel@165: moel@344: This Source Code Form is subject to the terms of the Mozilla Public moel@344: License, v. 2.0. If a copy of the MPL was not distributed with this moel@344: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@165: moel@344: Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org> moel@344: moel@165: */ moel@165: moel@165: using System.Collections; moel@165: using System.Collections.Generic; moel@165: moel@165: namespace OpenHardwareMonitor.Collections { moel@167: moel@165: public class ListSet<T> : IEnumerable<T> { moel@165: moel@195: private readonly List<T> list = new List<T>(); moel@165: moel@165: public bool Add(T item) { moel@165: if (list.Contains(item)) moel@165: return false; moel@165: moel@165: list.Add(item); moel@165: return true; moel@165: } moel@165: moel@165: public bool Remove(T item) { moel@165: if (!list.Contains(item)) moel@165: return false; moel@165: moel@165: list.Remove(item); moel@165: return true; moel@165: } moel@165: moel@165: public bool Contains(T item) { moel@165: return list.Contains(item); moel@165: } moel@165: moel@165: public T[] ToArray() { moel@165: return list.ToArray(); moel@165: } moel@165: moel@165: public IEnumerator<T> GetEnumerator() { moel@165: return list.GetEnumerator(); moel@165: } moel@165: moel@165: IEnumerator IEnumerable.GetEnumerator() { moel@165: return list.GetEnumerator(); moel@165: } moel@165: } moel@165: }