I'm trying to upcast a parameter passed as an object (which is an upcast of an object of type IEnumerable) to IEnumerable where Foo implements IFoo.
Here is an example of what I'd like to do but it does not work.
public void F(object o)
{
//I know the object o is of type IEnumerable<Foo> where Foo implements IFoo
IEnumerable<IFoo> ifoos = (IEnumerable<IFoo>) o);
}
Is there a work around? I don't want to make the function F Foo specific but I cannot get it to cast to the Interface Unless I do:
IEnumerable<IFoo> ifoos = (IEnumerable<Foo>) o).Select( f => (IFoo) f);
Thanks
Giuseppe