How can i make the following code compile?
Action<MyClass<object, object>> func = x => Console.WriteLine(x.ToString());
public void Apply<T1, T2>(MyClass<T1, T2> target)
{
func.Invoke(target);
}
I know it doesnt work because a MyClass<T1, T2> isnt a MyClass<object, object>, but what can i do?
Can i make the function generic? or Can i cast target?
either way, how?
If it helps, nothing in the func will ever do anything T1 or T2 specific. I know this assumption could make it fragile, but unit tests should catch any issues.
Edit: I'm avoiding the problem at the moment with loads of empty interfaces that i'd rather do away with!
Thanks