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