According to MSDN, ArrayList.Adapter(IList) does the following:
Adapter does not copy the contents of IList. Instead, it only creates
an ArrayList wrapper around IList; therefore, changes to the IList
also affect the ArrayList.
Is there a reverse operation that takes an ArrayList and returns a generic IList<T> wrapper? i.e. A method that returns an IList<T> such that the source ArrayList also updates when the IList<T> changes?
e.g.
ArrayList foo = new ArrayList();
foo.Add(new Bar());
foo.Add(new Bar());
IList<Bar> foobar = foo.GenericAdapterMethod(); // insert the method I'm looking for here
foobar.Add(new Bar());
Console.WriteLine(foo.Count); // this should return 3
Well, since ArrayList implements IList, technically this also solves the reverse problem, since to this method you can pass an ArrayList and it returns a subclass of IList (unless of course you really care to get back a generic IList).
Edit: Since what you want is in fact IList, you can use inheritance to create a subclass of ArrayList and write the method that you need. The problem is that inside the subclass of ArrayList you still need to have a concrete class backing up the IList object that you are returning, otherwise there is no way to add objects to both lists.