I have a method with declaration like this:
public void OriginalMethod(Func<object,bool> selector)
And I would like to call it from generic method, that has declaration like this:
public void GenericMethod<T>(Func<T, bool> selector)
How do I do that?
You can’t pass the
selectordirectly toOriginalMethod: it expects a method that accepts anyobject, but aFunc<T, bool>accepts only an object of typeT.Of course, you can cheat:
But if
OriginalMethodcalls the method with an object that is not convertible to T, it will fail…