76 lines
2 KiB
C#
76 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace JD.Collections.ObjectModel
|
|
{
|
|
/// <summary>
|
|
/// A read-only implementation of the <see cref="ICollection{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 ReadOnlyCollection<T> : ReadOnlyCollectionBase<T>
|
|
{
|
|
#region Variables
|
|
|
|
private readonly ICollection<T> m_wrappedCollection;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Creates a ReadOnlyCollection wrapped around the given collection.
|
|
/// </summary>
|
|
/// <param name="wrappedCollection">Collection to wrap.</param>
|
|
public ReadOnlyCollection(ICollection<T> wrappedCollection)
|
|
{
|
|
Throw.IfNull(wrappedCollection, "wrappedCollection");
|
|
m_wrappedCollection = wrappedCollection;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Wrapped members
|
|
|
|
/// <summary>
|
|
/// Count.
|
|
/// </summary>
|
|
public override int Count
|
|
{
|
|
get { return m_wrappedCollection.Count; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetEnumerator.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override IEnumerator<T> GetEnumerator()
|
|
{
|
|
return m_wrappedCollection.GetEnumerator();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Contains.
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public override bool Contains(T item)
|
|
{
|
|
return m_wrappedCollection.Contains(item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// CopyTo.
|
|
/// </summary>
|
|
/// <param name="array"></param>
|
|
/// <param name="arrayIndex"></param>
|
|
public override void CopyTo(T[] array, int arrayIndex)
|
|
{
|
|
m_wrappedCollection.CopyTo(array, arrayIndex);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|