using System; using JD.Collections.Interfaces; using JD.Kernel.StaticHelpers; namespace JD.Collections.ObjectModel { /// /// A read-only implementation of the interface. /// Methods that modify the collection throw a NotSupportedException, methods that don't /// modify are forwarded through to the wrapped collection. /// [Serializable] public class ReadOnlyObservableCollection : ReadOnlyCollection, IObservableCollection { #region Variables private readonly IObservableCollection m_wrappedCollection; #endregion #region Constructor /// /// Creates a ReadOnlyCollection wrapped around the given collection. /// /// Collection to wrap. public ReadOnlyObservableCollection(IObservableCollection wrappedCollection) : base(wrappedCollection) { Throw.IfNull(wrappedCollection, "wrappedCollection"); m_wrappedCollection = wrappedCollection; } #endregion #region Properties /// /// Access the internal wrapped collection. /// protected IObservableCollection WrappedCollection { get { return m_wrappedCollection; } } #endregion #region IObservableCollection Members public bool IsUpdating { get { return m_wrappedCollection.IsUpdating; } } void IObservableCollection.BeginUpdate() { MethodModifiesCollection(); } bool IObservableCollection.EndUpdate() { MethodModifiesCollection(); return false; } public event EventHandler> CollectionChanged { add { m_wrappedCollection.CollectionChanged += value; } remove { m_wrappedCollection.CollectionChanged -= value; } } #endregion } }