I have class that wants an IList
, but I have a Systems.Collection.IList
, coming from an NHibernate quere.
I want to create a method th
Cast
and OfType
return IEnumerable
implemetnations, not IList
implementations, so they wouldn't be useful to you.
Calling .Cast
will result in an extra copy of the list, which may have adverse performance implications.
A better (IMHO) approach would be to just create a wrapper class and do the conversion on the fly. You want something like this:
class ListWrapper : IList
{
private IList m_wrapped;
//implement all the IList methods ontop of m_wrapped, doing casts
//or throwing not supported exceptions where appropriate.
//You can implement 'GetEnumerator()' using iterators. See the docs for
//yield return for details
}
That will have the advantage of not create another copy of the entire list.