Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Recently while working on a project of mine and doing some refactoring I got an idea to write a custom tool to help me analyze my code in a very specific context and perform some very custom refactoring.

What I wish to do is to interface with Visual Studio somehow and use its powers to analyze my code and do some refactoring. There is a class view which displays the logical structure of a project with its classes, methods and variables so I assume the high-level information about the code is available. The question is, does it get exposed to the user? Is there some API for me to use?

Basically I want the following:

  1. A way to run some simple code analysis code blocks with the complexity of unit tests, nothing really fancy. Like getting the list of the classes matching a certain name pattern, iterate through their methods, filter the ones with certain attributes, look inside if there are calls to certain methods if so assert those calls having specific parameters. Then throw the analysis result into the output window, so that when I double-click there a location in the respective code file is opened in the workspace.

  2. A possibility to command Visual Studio to perform surgical refactoring like renaming a specified variable and then applying its built-in renaming refactoring project-wide. These basic refactoring operations are available for the user in manual mode, can they be invoked from code?

  3. Nothing that would damage the code style. Like the built-in refactoring which leaves the code style intact.

  4. Not a static plugin for Visual Studio but solution-dependent code, so that it travels with the solution. Without installation. Perhaps like a separate analysis project in a solution, which I can set as active, uncomment the desired analysis methods and let them run.

  5. Something very basic, without a GUI. A configuration file and the analysis code files will do.

  6. Possibly without using any third-party tool, don't wish to introduce an extra dependency

If it is at all possible, can you please give me some clues to the names, keywords, what to google for? I'm interested in any information you can provide to the subject - outline the scope of my options, known issues, difficulties, problems? Anything to make the big picture clear.

And a million dollar question: provided it's possible, can something like that be quickly hacked together in a few hours?

share|improve this question
2  
...Provided it's possible, can something like that be quickly hacked together in a few hours?: Heck no. With 19.8k points, I thought you'd know better. –  Jim G. Jun 20 '11 at 11:55
    
I find it sad that not only did I not get many answers but people have shown no interest in this question at all. Have no idea what if anything interests this community... –  user8685 Jun 29 '11 at 14:55
add comment

2 Answers

up vote 3 down vote accepted

Take a look at how other code refactoring tools are working.

I use CodeRush from DevExpress and it is shipped with full source code.

What is nice with CodeRush is its extensibility. Rules and features can be extended. Here are som example:

ReSharper from JetBrains, another popular refactoring tool, can be extended too.

Creating an extension is a few hours may not be that hard I think. However creating a completely new refactoring tool will require much more time. I guess, months of work.

share|improve this answer
add comment

We use FxCop tool for analysing code against custom rules created according to client coding standards. Now, this has become a part of Visual Stuido since VS 2008. There is no need to download/install anything else.

Check the following link:

http://blogs.msdn.com/b/codeanalysis/archive/2010/03/26/how-to-write-custom-static-code-analysis-rules-and-integrate-them-into-visual-studio-2010.aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.