Typed collection
.Net 1 style. IComponent is implemented so Visual Studio can recognise it in databinding.
Replace Entity with actual type and change the "using".
In .Net 2 just use List<T> or inherit from Collection<T> and override InsertItem/SetItem and ClearItem
using System;
using System.Collections;
using System.ComponentModel;
using MyApp; //replace this
[DesignerCategory("Code")]
public class TypedCollection : CollectionBase, IComponent
{
private ISite _site = null;
// Default constructor
public TypedCollection()
{
}
public Entity this[int index]
{
get { return InnerList[index] as Entity; }
set { InnerList[index] = value; }
}
#region IComponent Members
ISite IComponent.Site
{
get { return _site; }
set { _site = value; }
}
#region Implement the IDisposable members (IComponent inherits from IDisposable)
public event EventHandler Disposed;
void IDisposable.Dispose()
{
// Nothing to dispose here
if (Disposed != null)
Disposed(this, EventArgs.Empty);
}
#endregion
#endregion
public int Add(Entity entity)
{
return InnerList.Add(entity);
}
public void Remove(Entity entity)
{
InnerList.Remove(entity);
}
}