[Serializable] public class LazyLoadList<T> : IList<T>, System.Collections.IList,ISetLoadInfo { private IList<T> mItems = null; protected IList<T> Items { get { if (mItems == null) { LoadData(); } return mItems; } } private void LoadData() { if (Driver == null) { mItems = new List<T>(); return; } using (HFSoft.Data.IDataSession session = HFSoft.Data.MappingContainer.ConfigContainer.OpenSession(Driver, ConnectionString)) { session.Open(); IQuery query = Relation.GetRightQuery(session,Expression); mItems = query.List<T>(); } } IList 成员#region IList<T> 成员 int IList<T>.IndexOf(T item) { return Items.IndexOf(item); } void IList<T>.Insert(int index, T item) { Items.Insert(index, item); } void IList<T>.RemoveAt(int index) { Items.RemoveAt(index); } T IList<T>.this[int index] { get { return Items[index]; } set { Items[index] = value; } } #endregion ICollection 成员#region ICollection<T> 成员 void ICollection<T>.Add(T item) { Items.Add(item); } void ICollection<T>.Clear() { Items.Clear(); } bool ICollection<T>.Contains(T item) { return Items.Contains(item); } void ICollection<T>.CopyTo(T[] array, int arrayIndex) { Items.CopyTo(array, arrayIndex); } int ICollection<T>.Count { get { return Items.Count; } } bool ICollection<T>.IsReadOnly { get { return ((ICollection<T>)Items).IsReadOnly; } } bool ICollection<T>.Remove(T item) { return Items.Remove(item); } #endregion IEnumerable 成员#region IEnumerable<T> 成员 IEnumerator<T> IEnumerable<T>.GetEnumerator() { return Items.GetEnumerator(); } #endregion IEnumerable 成员#region IEnumerable 成员 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return Items.GetEnumerator(); } #endregion IList 成员#region IList 成员 int System.Collections.IList.Add(object value) { return ((IList)Items).Add((T)value); } void System.Collections.IList.Clear() { Items.Clear(); } bool System.Collections.IList.Contains(object value) { return Items.Contains((T)value); } int System.Collections.IList.IndexOf(object value) { return Items.IndexOf((T)value); } void System.Collections.IList.Insert(int index, object value) { Items.Insert(index, (T)value); } bool System.Collections.IList.IsFixedSize { get { return ((IList)Items).IsFixedSize; } } bool System.Collections.IList.IsReadOnly { get { return ((IList)Items).IsReadOnly; } } void System.Collections.IList.Remove(object value) { Items.Remove((T)value); } void System.Collections.IList.RemoveAt(int index) { Items.RemoveAt(index); } object System.Collections.IList.this[int index] { get { return Items[index]; } set { Items[index] = (T)value; } } #endregion ICollection 成员#region ICollection 成员 void System.Collections.ICollection.CopyTo(Array array, int index) { ((IList)Items).CopyTo(array, index); } int System.Collections.ICollection.Count { get { return Items.Count; } } bool System.Collections.ICollection.IsSynchronized { get { return ((IList)Items).IsSynchronized; } } object System.Collections.ICollection.SyncRoot { get { return ((IList)Items).SyncRoot; } } #endregion [NonSerialized] internal HFSoft.Data.IDriver Driver; [NonSerialized] internal string ConnectionString; [NonSerialized] internal HFSoft.Data.Expressions.Expression Expression; [NonSerialized] internal RelationAttribute Relation; ISetLoadInfo 成员#region ISetLoadInfo 成员 void ISetLoadInfo.SetInfo(HFSoft.Data.IDriver driver, string connstring, HFSoft.Data.Expressions.Expression expression, RelationAttribute relation) { Driver = driver; ConnectionString = connstring; Expression = expression; Relation = relation; } #endregion } interface ISetLoadInfo { void SetInfo(HFSoft.Data.IDriver driver, string connstring, HFSoft.Data.Expressions.Expression expression,RelationAttribute relation); }