using System; using System.Collections.Generic; using System.Linq; using Chernobyl.Utility; namespace Chernobyl.Collections.Generic.Event { /// /// A list type that extends an IList using the decorator pattern /// (http://en.wikipedia.org/wiki/Decorator_pattern) by giving it add and /// removal events. /// /// The type that is to be held within the list. public class DecoratingEventList : EventList { /// /// Constructor that creates an event list that uses a /// as it's internal list implementation. /// public DecoratingEventList() : this(new List()) {} /// /// Constructor. /// /// The being /// decorated or extended with event capabilities. public DecoratingEventList(IList listDecorated) { listDecorated.ThrowIfNull("list"); _listDecorated = listDecorated; } /// /// The being decorated or extended with event /// capabilities. /// protected override IList ListDecorated { get { return _listDecorated; } } /// /// The backing field to . /// readonly IList _listDecorated; } /// /// Extensions and utilities for and /// related types. /// public static class DecoratingEventListExtensions { /// /// Creates an from an /// . /// /// The type of the elements of source. /// The to create a /// from. /// A that contains elements from the /// input sequence. /// Thrown if /// is null. public static EventList ToEventList(this IEnumerable source) { source.ThrowIfNull("source"); return source.ToList().ToEventList(); } /// /// Creates an from an /// . /// /// The type of the elements of source. /// The to create a /// from. /// A that contains elements from the /// input sequence. /// Thrown if /// is null. public static EventList ToEventList(this IList source) { return new DecoratingEventList(source); } } }