I was reading a post at VS 2008, ASP.NET: Generate Local Resources.
Mehdi Golchin showed us a beautiful job of StateManagedCollection.
However I was wondered about using multiple classes of IStateManager in one StateManagedCollection.
As you can see below:
public class MenuItemCollection : StateManagedCollection
{
public MenuItem this[int index]
{
get { return (MenuItem)((IList)this)[index]; }
}
public int Add(MenuItem item)
{
return ((IList)this).Add(item);
}
public void Remove(MenuItem item)
{
((IList)this).Remove(item);
}
// Write Insert and RemoveAt methods
protected override void SetDirtyObject(object o)
{
((MenuItem)o).SetDirty();
}
}
This MenuItemCollection class can have only one child class(“MenuItem”).
If I want to use another class as well as MenuItem class, for example MenuItem2 class, how do I have to write the codes?
Anyone can help me?
Thanks in advance.
Write a generic version – for example,
And use it as
EDIT:
I have most probably mis-understood your question! Assuming now that you want to put two different type of objects into the
StateManagedCollection. From usage perspective, it doesn’t make sense to have objects of completely unrelated types into the collection – you need to have some base class. For example, consider DataControlFieldCollection which holds instances of (abstract) type ‘DataControField. BoundField, ButtonField etc inherits fromDataControField`.So you need to go via similar route – for example,
Note: Untested code