//New BSD License (BSD)
//http://bluecms.codeplex.com/license
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace BlueCMS.Core.Helpers
{
public class LazyList : IList
{
public LazyList()
{
inner = new List();
}
public LazyList(IQueryable query)
{
this.query = query;
}
private IQueryable query;
private IList inner;
public int IndexOf(T item)
{
return Inner.IndexOf(item);
}
public void Insert(int index, T item)
{
Inner.Insert(index, item);
}
public void RemoveAt(int index)
{
Inner.RemoveAt(index);
}
public T this[int index]
{
get { return Inner[index]; }
set { Inner[index] = value; }
}
public void Add(T item)
{
inner = inner ?? new List();
Inner.Add(item);
}
public void Add(object ob)
{
throw new NotImplementedException("This is for serialization");
}
public void Clear()
{
if (inner != null)
Inner.Clear();
}
public bool Contains(T item)
{
return Inner.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
Inner.CopyTo(array, arrayIndex);
}
public bool Remove(T item)
{
return Inner.Remove(item);
}
public int Count
{
get { return Inner.Count; }
}
public bool IsReadOnly
{
get { return Inner.IsReadOnly; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return Inner.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
return ((IEnumerable)Inner).GetEnumerator();
}
public IList Inner
{
get
{
if (inner == null)
inner = query.ToList();
return inner;
}
}
}
}