- ALists2.zip
- Bin
- Collections
- Release.NET4
- Loyc.Collections.dll
- Loyc.Collections.pdb
- Loyc.Collections.XML
- Loyc.Essentials.dll
- Loyc.Essentials.pdb
- Loyc.Essentials.xml
- nunit.framework.dll
- Essentials
- Release.NET4
- nunit.framework.dll
- Src
- ALists2-noexe.zip
|
/*
* Created by SharpDevelop.
* User: Pook
* Date: 4/10/2011
* Time: 9:03 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>
/// Helper type returned from <see cref="LCExt.AsListSource{T}"/>.
/// </summary>
/// <summary>A read-only wrapper that implements ICollection and ISource.</summary>
[Serializable]
public sealed class ListAsListSource<T> : WrapperBase<IList<T>>, IList<T>, IListSource<T>
{
public ListAsListSource(IList<T> obj) : base(obj) { }
public int Count
{
get { return _obj.Count; }
}
public bool Contains(T item)
{
return _obj.Contains(item);
}
public T this[int index]
{
get { return _obj[index]; }
set { throw new NotSupportedException("Collection is read-only."); }
}
public T this[int index, T defaultValue]
{
get {
if ((uint)index >= (uint)_obj.Count)
return defaultValue;
else
return _obj[index];
}
}
public T TryGet(int index, ref bool fail)
{
if ((uint)index < (uint)_obj.Count)
return _obj[index];
fail = true;
return default(T);
}
public int IndexOf(T item)
{
return _obj.IndexOf(item);
}
IRange<T> IListSource<T>.Slice(int start, int count)
{
return new Slice_<T>(this, start, count);
}
public Slice_<T> Slice(int start, int count)
{
return new Slice_<T>(this, start, count);
}
#region IList<T> Members
public void Insert(int index, T item)
{
throw new NotSupportedException("Collection is read-only.");
}
public void RemoveAt(int index)
{
throw new NotSupportedException("Collection is read-only.");
}
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.