[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Expand]Unit Testing Assistance
 [Expand]Decompiling Tools
 [Expand]Configuration Options
   Adding a Dictionary for the Spell Checker
  [Collapse]Custom Templates Creation
    Adding a Template
    Using Text Commands
    Referencing Namespaces
    Linking Identifiers
    Providing Input Fields
    Using Variables
    Iterating Through Elements
    Template Name Variables
    Alternative Template Expansions
   [Expand]Text Commands
    String Providers
  [Expand]Context Providers
   Specify a Default Filter for the Jump to Symbol Window
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Alternative Template Expansions

This topic shows you how to enable Alternative Expansions for a template. You will specify several template expansions that will be used in different Contexts. The example starts with the vi?Type? template described in the Template Name Variables topic.

  1. Fill the Context field in the original template. It should expand when the clipboard does not contain an identifier. To check this, use the logically-inverted [HasIdentifier] Context Provider from the Editor | Clipboard group.
  2. Click the + button on the Template Expansion toolbar to add an Alternative Expansion.

  3. Specify the context for this expansion. For instance, use the following context: "[Hasldentifier] && ![DeclaresLocal(«?Paste»)]". This expression checks whether or not the clipboard holds a valid identifier and this identifier is free in the current scope. If so, you can use this identifier to suggest the name for the new variable.


    To check if the identifier is declared locally, use the [DeclaresLocal(localName)] context provider from the Editor | Code group. You can use any String Provider as the Context Provider's parameter.

  4. Add one more expansion to cover the case when the identifier in the clipboard is already declared. In this case, you can assign a new variable value without declaration.

The template with three Alternative Expansions is now fully defined, and you can save and test it.

Is this topic helpful?​​​​​​​