Archive

Archive for the ‘Code Samples’ Category

Creating a command line tool for source code metrics analysis

August 10th, 2011 Comments off

Recently, we have created a console application that parses an entire solution and shows summary information about declared types and the number of members in each type. Let’s tweak it a bit, so it provides more meaningful and useful information, such as a report of Maintenance Complexity (MC) code metric for a solution source code.

Read more…

How to edit source files of an entire Visual Studio solution using DXCore

July 4th, 2011 Comments off

Usually, simple edits of text files are accomplished using the TextDocument object, which represents an open source file inside the IDE. The text document object is easy to access through the Documents DXCore service. It has lots of useful methods for editing a text like InsertText, DeleteText and SetText, which take a source code coordinates and a new text for replacement as a parameters. However, to use a text document object, it is required for the file to be opened inside the Visual Studio environment. If a file is closed, there’s no TextDocument object assigned to the file and you simply can’t use its methods. In case you are going to edit closed and/or multiple files, there’s a better way – the FileChange object (in the DevExpress.CodeRush.Core.Replacement namespace).

Read more…

Populating the User Guide with dynamic and static content

June 17th, 2011 Comments off

IDE Tools User Guide supports static and dynamic content. The static text is stored inside the “*.htm” files, and the pictures are stored in the independent files in the appropriate format (gif, jpeg, png, etc). The static content can be manually edited right inside of the User Guide. There are also two DXCore controls useful for population dynamic content. These controls are the Tutorial Page Provider and Tutorial Content Provider. In this article, we’ll add some static content to the built-in CodeRush Documentation shown inside User Guide, and provide some dynamic content using the Tutorial Content Provider component.

Read more…

How to use DXCore in a Console App outside of Visual Studio

June 2nd, 2011 2 comments

Actually, DXCore is not designed to be used outside of Visual Studio, but there are always workarounds… In this article I’m going to show you how to use the DXCore Framework inside the regular C# Console Application to parse an entire solution and work with the abstract parsed tree. The solution should be passed-in as an argument to the program as a full complete path to the *.sln file. If there’s no argument used, the hard-coded path to the test program is used, so the program will parse itself and print information about the solution, such as a list of all types used and the number of members inside of each class.

Read more…

How to add new menu entries to specific Visual Studio dropdown or context menus

May 3rd, 2011 Comments off

Adding a new menu entry can be easily achieved using the Action DXCore control. Just set the ParentMenu property to the name of the menu, where you would like the new item to appear. As an alternative, you can set the CommonMenu to one of the suggested values. The CommonMenu property has the DevExpress.CodeRush.Menus.VSCommonBar enumeration type, which enumerates most of common Visual Studio menu names, such as File, Edit, View, Tools, DevExpress, Help, etc.

Read more…

How to load/change CodeRush templates from inside your DXCore plug-in

April 22nd, 2011 Comments off

CodeRush code templates are stored inside serialized objects (binary and XML files) as opposed to usual DXCore plug-ins settings storage mechanism. If you’d like to load templates (e.g. to dump and print some templates categories) you can use the DXCore Templates and Serialization services.

Read more…

How to read/write different DXCore setting files from your own plug-in

April 22nd, 2011 Comments off

Sometimes, when developing a DXCore plug-in, you might need to know what settings other CodeRush or Refactor! features have. For example, it might be necessary to know if the particular feature is enabled or disabled to not intersect with it; or change a feature’s default settings from inside your own plug-in. This way, you can tweak any settings programmatically without opening the Options Dialog.

Read more…

How to parse source code using the DXCore integrated code parsers

April 11th, 2011 3 comments

There are times when you need to parse specific source files or blocks of code. Obviously, the DXCore Framework has many built-in parsers for various programming languages. They can be used inside the Visual Studio environment, or outside an IDE in any other application type, such as a Console App, for example. Later, this kind of app (a Console App) can be used in the project building process for code validation, code clean-up, automatic refactoring and any other task.

Read more…