Is there any way at compile time to assert an argument Func is static?
This seems like something the compiler could easily check rather than relying on runtime failure.
I realise it can be done at runtime with [arg].Method.IsStatic
Cheers
This seems like something the compiler could easily check rather than relying on runtime failure.
Yes, it absolutely could - but only if there's something in the language to prompt it to do so. There isn't, in C# - it's a pretty odd requirement, IMO, and one which doesn't play nicely with lambda expressions.
With VS 2015 you could easily write a Roslyn CodeDiagnostic to spot this and throw up a warning or error. You'd probably want to decorate the parameter with an attribute for the diagnostic to spot, and then check all callers.
See more on this question at Stackoverflow