This is a very short post to demonstrate the concept that I mentioned in parting during the last post.
‘And of course I could eliminate the method call tracker altogether if I made use of lambda expressions and parsed the expression tree to see what method was called’
Someone fired an email asking how to do this so I thought I would quickly implement to show them the result. You can now also set filters on the interceptor by use of a lambda expression. So instead of this (and you can still do this):
You can now use a lambda expression which negates the need to store a reference to the constraint to apply constraints:
1 2 3
The InterceptCallTo method accepts an ExpressionTree of type Action
1 2 3 4 5
Notice that the method returns the InterceptorConstraint itself, which is what allows for the very limited fluent interface. As far as parsing the expression to store the method to be intercepted on, it is all done by the MethodCallTracker itself:
1 2 3 4 5
That’s it, that’s all. The AddCallFor method is now called from both here and the original Interception tracker to store the list of methods that should be intercepted on.
Develop with Passion!!