You just plain cannot use expression trees in your case, they only get compiler support in later versions. But you don't need to, if the only reason you use it is to get the MethodInfo
in a strongly-typed fashion.
public sealed class MyClass
{
private static readonly GenericStaticMethod _deserializeHelper = new GenericStaticMethod(new Action<object, object, object>(DeserializeHelper<object>));
}
public sealed class GenericStaticMethod
{
private readonly MethodInfo methodToCall;
public GenericStaticMethod(Delegate methodCall)
{
methodToCall = methodCall.Method.GetGenericMethodDefinition();
}
}
You'll need to change Action<object, object, object>
to a delegate type that matches the signature of DeserializeHelper<object>
.