Say I have the following:
public interface IFoo
{
}
public interface IBar : IFoo
{
void Bar();
}
public interface IUber : IFoo
{
void Uber();
}
Is there a way of doing the following?
List<IFoo> list = new List<IFoo>();
void BarAll()
{
foreach(IBar o in list)
o.Bar();
}
void UberAll()
{
foreach(IUber o in list)
o.Uber();
}
Currently this works, but only for objects which are both IBar and IUber, I need it to work in cases where an object is only one of those. (Currently I can an unable to cast error)
Is this even possible? Or something similar?