Hi Guinness,
Here is my new class supporting all sort that ArrayList has + type safety.
class MyList: CollectionBase
{
public ArrayList mInnerArrayList;
public MyList()
{
mInnerArrayList = ArrayList.Adapter(this.InnerList);
}
public QRow this[int index]
{
get{return (QRow)InnerList[index];}
set{InnerList[index] = value;}
}
public int Add(QRow value)
{
return InnerList.Add(value);
}
public void Remove(QRow value)
{
InnerList.Remove(value);
}
public void Sort()
{
mInnerArrayList.Sort();
}
protected override void OnValidate(object value)
{
base.OnValidate (value);
if(!(value is QRow)) throw new ArgumentException("Type of the
value is not acceptable");
}
}
You can add the second overload of the *sort* method as well as other
ArrayList operations that you miss in CollectionBase.
HTH
B\rgds
100
"Guinness Mann" <GM***@dublin.com> wrote in message
news:MP************************@news.newsguy.com.. .
Hey, thanks, 100. I've copied your example into my snippets for
possible use on another project. In this case, though, I really want to
use ArrayList because of some of it's member functions (like Sort), and
it seems incredibly easy to simply add this:
public class QRowArray : ArrayList
{
public new QRow this[int i]
{
get { return (QRow)base[i]; }
set { base[i] = value; }
}
}
And be done with it. I understand that I, for instance, don't have type
safety on input data, but it's really just convenience code to keep all
the ugly casting out of the body of my code; it's not production code.
Have I violated any secret laws?
-- Rick
In article <eh**************@tk2msftngp13.phx.gbl>, 10*@100.com says... Hi,
This is the way I use CollectionBase when I want to create a strongly
typed collection
class MyList: CollectionBase
{
public QRow this[int index]
{
get{return (QRow)InnerList[index];}
set{InnerList[index] = value;}
}
public int Add(QRow value)
{
return InnerList.Add(value);
}
public void Remove(QRow value)
{
InnerList.Remove(value);
}
protected override void OnValidate(object value)
{
base.OnValidate (value); //if null is acceptable don't call
base implemetation
if(!(value is QRow)) throw new ArgumentException("Type of the
value is not acceptable");
}
}