|
/*
* Created by SharpDevelop.
* User: Pook
* Date: 4/10/2011
* Time: 9:27 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using Loyc.Essentials;
namespace Loyc.Collections
{
/// <summary>A read-only wrapper that implements ICollection(T) and ISource(T),
/// returned from <see cref="LCExt.AsSource{T}"/>.</summary>
[Serializable]
public sealed class CollectionAsSource<T> : WrapperBase<ICollection<T>>, ICollection<T>, IReadOnlyCollection<T>
{
public CollectionAsSource(ICollection<T> obj) : base(obj) { }
public int Count
{
get { return _obj.Count; }
}
public bool Contains(T item)
{
return _obj.Contains(item);
}
#region ICollection<T> Members
public void Add(T item)
{
throw new NotSupportedException("Collection is read-only.");
}
public void Clear()
{
throw new NotSupportedException("Collection is read-only.");
}
public void CopyTo(T[] array, int arrayIndex)
{
_obj.CopyTo(array, arrayIndex);
}
public bool IsReadOnly
{
get { return true; }
}
public bool Remove(T item)
{
throw new NotSupportedException("Collection is read-only.");
}
public IEnumerator<T> GetEnumerator()
{
return _obj.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return (_obj as System.Collections.IEnumerable).GetEnumerator();
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.