The following code would compile if foo
is casted to either a type implementing IEnumerable
or dynamic
. Is there a way to achieve the same without casting foo
?
I am aware I could do two methods and don't wish to force more constraint to T.
interface IDummy
{}
class FooBar<T> where T : class
{
void Bar(T foo)
{
if (foo is IEnumerable<IDummy>)
foreach (var item in foo)
B(item);
else if(foo is IDummy)
B(foo);
}
void B(IDummy item)
{
}
}