Question

I'd like to create my own auto-"Resolve" feature. In VS, when you right-click and choose "Resolve", it gives you options and upon selecting one, it adds the necessary "using ..." statement to that file.

I'd like to take it 2 steps further:

  1. I want to parse the text when there are changes to look for any references that might be needed, rather than underlining and waiting for the user to "Resolve".
  2. I want to not only provide a "using ..." statement, but also figure out which DLL to reference in the project. In VS, you only get "Resolve" if you already have the correct library referenced already.

Now, to keep the complexity down:

  1. I only care about built-in .NET libraries that ship with C#/VS/.NET.

I know there are a few cases where even the .NET classes overlap (e.g. Timer in System.Threading and System.Windows.Forms), but they're the exception.

So, my question is, is there some list/mapping I can grab that maps all the .NET classes to a "using ..." statement and a library reference (including standard file path)? Or, is there some way for me to automatically generate such a list?

Was it helpful?

Solution

you can look for 3rd party products that provides this. there is a great product ReSharper on the market that builds symbol data base from source code files (not from compiled code) which is also fast and optimized. It DOES allow you to resolve the symbol and add a reference to the assembly if it already knows this assembly from other projects in the solution. I believe it's not the only product.

Building the list of classes from system assemblies is not that hard. Simply make the list of system assemblies from standard install, load each of them and create list of public classes. Look at System.Reflection.Assembly methods, such as Load() and GetTypes()

OTHER TIPS

I think you can list the DLLs in GAC, and use reflection to list all the public classes for each DLL.

This way you can create a mapping, and figure out which reference to add and which using statement to add.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top