I have a generic method like this (simplified version):

public static TResult PartialInference<T, TResult>(Func<T, TResult> action, object param)
{
    return action((T)param);
}

In the above, param is of type object on purpose. This is part of the requirement.

When I fill in the types, I can call it like this:

var test1 = PartialInference<string, bool>(
    p => p.EndsWith("!"), "Hello world!"
);

However, I'd like to use type inference. Preferably, I would like to write this:

var test2 = PartialInference<string>(
    p => p.EndsWith("!"), "Hello world!"
);

But this does not compile. The best I came up with is this:

var test3 = PartialInference(
    (string p) => p.EndsWith("!"), "Hello world!"
);

The reason I would like to have this as a type parameter and still have the correctly typed return type is because my actual calls look something like this:

var list1 = ComponentProvider.Perform(
    (ITruckSchedule_StaffRepository p) => p.GetAllForTruckSchedule(this)
)

Which is very ugly and I would love to write as something like this:

var list2 = ComponentProvider.Perform<ITruckSchedule_StaffRepository>(
    p => p.GetAllForTruckSchedule(this)
)
Edit
Report