I want to call a generic method that constrains the input type T to implement two interfaces:
interface IA { }
interface IB { }
void foo<T>(T t) where T : IA, IB { }
How can I fix the last line of
void bar(object obj)
{
if (obj is IA && obj is IB)
{
foo((IA && IB)obj);
}
}
?
Reflection probably allows to do the call, but I would like to stay within the language.
Does the C# 4.0 dynamic keyword get you out of jail (mostly) free? After all – you are already doing the type checking.
Does that break if foo tries to cast the parameter to T? I don’t know.