Archive

Archive for the ‘Code Samples’ Category

How to detect if DXCore is loaded from another add-in

January 17th, 2011 Comments off

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

Here is a sample code illustrating how to detect if the DXCore is installed and loaded from another add-in (without static dependencies on the DXCore assemblies) using reflection. This could be helpful if your add-in functionality somehow intersects with the DXCore’s.

From inside a usual DXCore plug-in, you can detect if the DXCore is loaded by calling the “CodeRush.IsLoaded” property. In case you are not going to reference the DXCore assemblies inside your add-in, this sample might help.

Read more…

How to perform an existing refactoring from another one

December 25th, 2010 12 comments

Refactor! Pro has numerous refactorings which perform a single task. What if we could run several refactorings at once?

For example, there is a support for optimizing namespace references added to the Move Type to File refactoring: after the new file is created, the Optimize Namespace References refactoring does its job. Here are other examples of refactoring (code provider) combinations, which can be performed:

  • Introduce Local and Promote to Parameter will create a new refactoring, called something like “Introduce Parameter”.
  • Declare Class (Struct) and Declare Method (Property) will create a new multi-declare code provider, which will declare everything at once.
  • Introduce Parameter Object and Move Type to File will add a new option for the first refactoring to create a new file.
  • And so much more…

Read more…

How to show and dock a tool window automatically on Visual Studio start-up

November 15th, 2010 5 comments

If you’d like to show your tool window from a DXCore-based ToolWindow plug-in, you have to create another standard plug-in that will do this. You can add an additional DXCore standard plug-in project item into your solution, where the tool window is located. In the new plug-in, you need to handle the DXCoreLoaded event and manually add a code that opens and shows a tool window.

Read more…

How to add a file that depends upon another file

October 23rd, 2010 Comments off

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

To programmatically add a file to a specific project that depends upon another file (DependentUpon), you can use methods from the DXCore Solution service.

Consider the following solution structure:

DXCore Solution Explorer structure sample

Read more…

How to add a file to a particular project

October 22nd, 2010 Comments off

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

To programmatically add a file to a specific project, you can use the AddFileToProject method from the DXCore Solution service. Here is its definition:

public void AddFileToProject(string projectName, string filePath)

This method adds the specified file to the project with the given name. The project must be open in Visual Studio and be part of the active solution.

Read more…

How to programmatically verify a context

September 25th, 2010 Comments off

Here’s a sample code of how to programmatically verify a particular context inside of your DXCore plug-in. You may achieve this using the Context service like this:

CSharp code:

ContextResult result = CodeRush.Context.Satisfied(@"Focus\Documents\Source\Code Editor");
bool editorHasFocus = result == ContextResult.Satisfied;

Read more…