Home
Manage Your Code
Snippet: Collection Wrapper (C#)
Title: Collection Wrapper Language: C#
Description: This is a basic abstract class that implements IList<> and has an IsDirty boolean attached in order to assist with database saves. The class is generic, so it makes life very easy when you implement it. Views: 468
Author: Nathan Blevins Date Added: 1/15/2008
Copy Code  
1	public abstract class CollectionWrapper<T> : IList<T>
2	{
3		private List<T> _InnerList;
4
5		protected List<T> InnerList
6		{
7			get { return _InnerList == null ? new List<T>() : _InnerList; }
8			set { _InnerList = value; }
9		}
10
11		private bool _IsDirty;
12
13		public bool IsDirty
14		{
15			get { return _IsDirty; }
16			set { _IsDirty = value; }
17		}
18		#region IList<T> Members   ...		#endregion
52		#region ICollection<T> Members   ...		#endregion
97		#region IEnumerable<T> Members   ...		#endregion
105		#region IEnumerable Members   ...		#endregion
113	}
Usage
It is generics, so you simply have to inherit from it in order to transform your class into a collection object.