JD2022-TU1/main/tools/framework/JD.Collections/ObjectModel/ReadOnlyObservableList.cs

75 lines
No EOL
1.8 KiB
C#

using System;
using JD.Collections.Interfaces;
namespace JD.Collections.ObjectModel
{
/// <summary>
/// A read-only implementation of the <see cref="IObservableList{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 ReadOnlyObservableList<T> : ReadOnlyObservableCollection<T>, IObservableList<T>
{
#region Constructor
/// <summary>
/// Ctor.
/// </summary>
/// <param name="list"></param>
public ReadOnlyObservableList(IObservableList<T> list)
:base(list)
{ }
#endregion
#region Properties
/// <summary>
/// Access the wrapped collection.
/// </summary>
protected new IObservableList<T> WrappedCollection
{
get { return (IObservableList<T>)base.WrappedCollection; }
}
#endregion
#region IList implementation
/// <summary>
/// Default implementation
/// </summary>
public int IndexOf(T item)
{
return WrappedCollection.IndexOf(item);
}
/// <summary>
/// Default implementation
/// </summary>
public void Insert(int index, T item)
{
MethodModifiesCollection();
}
/// <summary>
/// Default implementation
/// </summary>
public void RemoveAt(int index)
{
MethodModifiesCollection();
}
/// <summary>
/// Default implementation
/// </summary>
public T this[int index]
{
get { return WrappedCollection[index]; }
set { MethodModifiesCollection(); }
}
#endregion
}
}