DXCore Components – ContractProvider
The ContractProvider DXCore component is used to extend the available contracts list for the Add Contract code provider shipped with Refactor! Pro and CodeRush Xpress.
The control doesn’t exist on the Visual Studio toolbox by default. You have to manually add it by selecting the “Choose Items…” in the context menu of the Visual Studio toolbox:
and locating the ContractProvider control in the list:
Now, you can drop the ContractProvider onto your plug-in design surface from Visual Studio Toolbox:
It’s not a visual control, only its properties and events should be tweaked. Here’s the Properties window, containing available properties, their categories and default values:
and the Events list:
The ContextProvider component is located in the “DevExpress.CodeRush.Core” assembly. It is derived from the “ContentProvider” base type:
Here’s a list of properties in alphabetical order with descriptions:
Property name |
Description |
ActionHintText | Gets or sets the text that will be displayed in an action hint after this provider is applied. |
AutoActivate | If true, this provider will be automatically activated while it is executing and deactivated afterwards. If false, the provider needs to call the Activate and Deactivate methods of this provder at the appropriate times. |
AutoUndo | If true, an undo unit will automatically be created to collect all text changes made by this provider during the Apply event. If false, the provider is responsible for handling the undo stack itself. |
CodeIssueMessage | Set a unique string that connects this content provider to a particular code issue. This string should also be passed to the ea.AddIssue() method, called from the IssueProvider’s CheckCodeIssues event. |
Description | Text, describing the purpose or behavior of this plug-in extension. This text may appear inside the User Guide, configuration UI, or the About box. |
DisplayName | The text name that identifies this extension. This text may appear inside the User Guide, configuration UI, or the About box. |
ExclusiveAvailabilityBehaviour | Determines what will happen when the Refactor action is invoked without parameters and this is the only provider available. Default behavior is to immediately apply the provider. However for certain providers having unexpected or potentially surprising side-effects, it may make more sense to show the popup menu, which provides an opportunity to review the impact (through the preview hint) before committing. |
Image | Sets the bitmap image for this smart tag item. Images are optional, but can be useful for displaying in the context menu or the popup menu. |
NeedsSelection | If true, this content provider requires a selection to determine availability. This is used by the Code Issues engine to select the range of the issue before a check is made (through the CheckAvailability event) to see if this content provider can provide a fix for the issue in question. |
ProviderName | The name of this provider. |
Register | If true, this extension will be available to the DXCore. Otherwise, it will be hidden. |
SupportsAsyncMode | If true, the CheckAvailability event handler is performed on a separate thread, instead of the main UI thread. |
Events:
Event name | Description |
Apply | Occurs when the provider needs to be applied. Handle this event to apply this provider to the currently existing code in the active text document. Note, that this event will never fire if the provider is not available so code that checks for provider availability is not necessary in a handler for this event. |
Cancelled | Occurs when this provider has been cancelled. Implement code that will cancel this provider inside a handler for this event. |
CheckAvailability | Occurs when the availability of this provider in the current context is being tested. Handle this event to indicate under what conditions this provider is available or recommended. |
GetAvailabilityContextString | Occurs before the smart tag manager determines the command order based on historic usage. If your provider has distinct states that you would like separate entries for, handle this event and assign a unique string to the Context property of the event arguments that represents the distinct state. For example, the Inline Temp provider handles this event and sets the Context property to “1” when only one instance of the temporary variable exists.” |
HidePreview | Occurs when a menu item inside the popup menu is no longer highlighted. This can happen when the user selects a different provider, when the user executes the selected provider, or when the popup menu closes. If you display visual information in the PreparePreview event, you should also handle this event to clean up the preview. |
LanguageSupported | Handle this optional event if you want to restrict your context to one or more programming languages. If you do not handle this event, the DXCore makes your context available in all programming languages. |
PreparePreview | Occurs when the user highlights this provider inside the popup menu. Handle this optional event to display any additional visual information that can preview the impact of this provider. If you handle this event, you should clean up your preview in a HidePreview event handler. |
SetUp | Occurs immediately before the Apply event is fired. Handle this optional event to perform any necessary setup before the provider is applied. |
TearDown | Occurs immediately after the Apply event is fired. Handle this optional event to perform any necessary clean up after the provider is applied. |
VisualStudioSupported | Handle this optional event if you want to restrict your provider to one or more Visual Studio versions. If you do not handle this event, your provider will be available in any Visual Studio version. |