I\'m trying to improve my reflection code by creating Delegates for the Getter
and Setter
methods.
My code looks like this:
MyO
If your objective is to be able to invoke your action/function without knowing the return type at compile time, then you probably want to end up with an Action
and Func
, right?
You can do this without having to compile an expression tree or anything, like so:
// Use reflection to create the action, invoking the method below.
var setAction = (Action
Using this helper method:
private static Action
My tests show this to be roughly 25% faster than using dynamic
, and about 45% slower than just saying obj.Prop = 2
;