How to tell which way an extension method has been invoked?

How can I tell how an extension method was called, I have access to the IInvokedExpression and the IMethod but I am unsure on how to tell.

e.g I want to know which one of the 2 possibilities was used:

var test = Observable.Merge(GenerateNumbers(34), GenerateNumbers(42));

or

var test = GenerateNumbers(34).Merge(GenerateNumbers(42));



ta

Ollie

2 comments
Comment actions Permalink

ReSharper finds out using the ExtensionMethodInvocationAnalyzer class (for the "invoke as extension method" suggestion when calling an extension method like a static method). I've only had a quick look at it, and I think it's going to be best to duplicate it and step through, to be sure what it's doing. It looks like it's taking a copy of the invocation of an extension method, replacing the qualifier with the first argument, removing the first argument and checking for equality with the original method, and checking that it still resolves. If all that is true, then it's an extension method being called as a static method. I think - I haven't run it.

It would be interesting to see how difficult it would be to see if the qualifier expression is a class or not. If so, and if the IMethod.IsExtensionMethod property is true, it's being invoked as a static method. If not, it's an extension method.

0
Comment actions Permalink

Matt - thanks for the info,

I think I'll give the second idea ago


ta

Ollie

0

Please sign in to leave a comment.