3

Is there any plug-in, or built-in way to locate extension methods in Visual Studio? Often I know that the method exists, but not the namespace its in. or if I copy a line of code from one location to another, it would make it easier to auto-resolve the using line.

They have already made it very easy to do this for resolving possible class locations by letting me right click on a type name and select "Resolve" which lists possible classes I could be looking for. I can't seem to find anything similar that would do it for extension methods.

Based on the number of SO questions asking why a Linq extension method doesn't work due to a missing using, it seems like this would be a pretty common need. Does anyone know of a way to do this? Thanks in advance.

Ocelot20
  • 10,510
  • 11
  • 55
  • 96
  • 2
    [Resharper](http://www.jetbrains.com/resharper/) can do this. – Mike Nov 06 '13 at 18:43
  • Should have specified: The "free-er" the better :). – Ocelot20 Nov 06 '13 at 18:44
  • Note that there are two cases. The easy one is if all that is missing is a `using` directive. The hard case is when then project is missing an assembly reference (the current file may or may not miss a `using` directive as well). – Jeppe Stig Nielsen Nov 06 '13 at 19:05
  • possible duplicate of [Tool to optimize C# using statements?](http://stackoverflow.com/questions/136001/tool-to-optimize-c-sharp-using-statements) – Agat Nov 06 '13 at 19:07
  • @Agat: That is the *opposite* of the problem I'm trying to solve. Also, Visual Studio now does what that question was asking. – Ocelot20 Nov 06 '13 at 19:16
  • The problem you have is related to the 'using' things. That's not a completely direct relationship, but all those things related to using Resharper solves: you just start typing your extension method, press Ctrl+Alt+space (for instance) -- and that's all. – Agat Nov 06 '13 at 19:26
  • @Agat: The same answer does not mean its the same question :). Resharper is a fine answer to both, but the point of identifying duplicates is to help with searching for the best solution to a given problem. If each question can have *other* answers, then marking them as duplicates detracts from both questions. – Ocelot20 Nov 06 '13 at 19:46
  • @Ocelot20. "The same" sometimes might be pretty philosophical category. For me those ones sound the same. I have a right to think so, the same way as flag it in certain way. If you have any other thoughts -- you can easily flag the question in your way. If many people decide the same as me -- well, what we can done -- that means it's the same. That's why this functionality is implemented on the site. (I guess). And this is how democracy works. (I guess). he he – Agat Nov 06 '13 at 19:55

3 Answers3

2

Have a look at this SO question :

What are some alternatives to resharper?

I know it is pricey but Resharper is amazing.

Community
  • 1
  • 1
David Pilkington
  • 13,528
  • 3
  • 41
  • 73
1

Yes. There is such perfect "extension". Its name is "Resharper". But it's not free.

Agat
  • 4,577
  • 2
  • 34
  • 62
0

If it's an extension you've used before, usually I do a Ctrl+Shift+F file search to find existing usage, then hit F12 for Go To Definition and that will take you to where it was defined so you can copy and paste from there the namespace it's declared in. This works even if it's an extension that is in another DLL because Go To Defintion will show you the metadata file which will have the namespace in it.

I wish there was a better way.

If its an extension you know is in your current solution(rather than just being imported through a DLL), you can put it's name in the "Search Solution Explorer" box at the top of the solution explorer. (Note that is a case sensitive field if you type any upper case characters, it's case insensitive if they are all lower case, kind of funky).

AaronLS
  • 37,329
  • 20
  • 143
  • 202