JetBrains Fleet 1.37 Help

Postfix templates in C#

Postfix templates help you transform expressions that you have already typed without jumping backwards — just type a dot after an expression and pick a template from the completion list.

Apply postfix templates

One of the simplest examples of postfix templates is negating a boolean expression. Suppose you have just typed a boolean expression and then realized that the comparison logic should be reversed. Normally, you have to move your caret back and change == to != or vice versa, and then return to where you were. With JetBrains Fleet, you can just continue typing .not and press Enter.

There are a lot more postfix templates that you can use to speed up coding. For example, you can wrap the current expression with if, while, lock, using, add return, yield return, await in front of the current expression, iterate over a collection, generate a switch statement, cast the expression to a specific type, or even introduce a field or property for the expression.

Postfix template could even change your typing routine. Consider the CheckInput method below and imagine how you would type the null-checking clause.

private void CheckInput(string input) { if (input == null) { throw new ArgumentNullException("The input is null"); } // do something with 'input' }

Now let's see how you could do it with postfix templates.

As soon as your caret is in the method body, you can start typing input right away because that is what you want to check. When the input is there, just continue typing .null - a postfix template for checking the expression for null:

Applying postfix template for null-check

This will compare input with null and wrap the comparison in an if statement, and place the caret at the position where you can continue typing:

Applying postfix template for null-check

Now, instead of typing throw, you can go ahead with typing the exception class name, and invoke the .throw template after it:

Applying postfix template for null-check

After applying this template, you have the complete throw statement, and the caret at a place to enter arguments:

Applying postfix template for null-check

You could see that instead of typing frequently used language constructs manually, in many cases you can type just a couple of initial characters of a template shortcut and get everything in place, properly formatted and without typos.

Apply a postfix template

  1. Type a dot after the current expression and check the completion list for the desired templates.

  2. If you know the shortcut of the template that you are going to apply, start typing it — this will shrink the list of suggestions.

  3. As soon as the desired template is selected in the suggestion list, press Enter.

  4. If the template has editable parameters (that is, requires user input), JetBrains Fleet deploys a hot spot session in the editor and sets the input position at the first parameter. Then you can do the following:

    • If JetBrains Fleet suggests some values for the current parameter, use Up and Down arrow keys to navigate through the list of suggested values, or just type in a desired value.

    • Press Tab or Enter to accept the value and move to the input position of the next parameter. If this is the last parameter, the hot spot session completes and the caret moves to the end position defined for the session.

    • Press Shift+Tab to move the input focus to the input position of the previous parameter.

    • Press Esc to exit the hot spot session. In this case, all session parameters will be initialized with default values.

List of postfix templates





Surrounds expression with invocation



Awaits expressions of 'Task' type

await expr


Surrounds expression with cast

((SomeType) expr)


Checks boolean expression to be 'false'

if (!expr)


Introduces field for expression

_field = expr;


Iterates over collection with index

for (var i = 0; i < xs.Length; i++)


Iterates over enumerable collection

foreach (var x in expr)


Iterates over collection in reverse with index

for (var i = xs.Length-1; i >= 0; i--)


Checks boolean expression to be 'true'

if (expr)


Surrounds expression with lock block

lock (expr)


Produces instantiation expression for type

new SomeType()


Negates boolean expression



Checks expression to be not-null

if (expr != null)


Checks expression to be null

if (expr == null)


Parenthesizes current expression



Parses string as value of some type



Introduces property for expression

Property = expr;


Returns expression from current function

return expr;


Selects expression in editor

|selected + expression|


Produces switch statement

switch (expr)


Throws expression of 'Exception' type

throw expr;


Assigns current expression to some variable

lvalue = expr;


Parses string as value of some type

int.TryParse(expr, out value)


Wraps type usage with typeof() expression



Wraps resource with using statement

using (expr)


Introduces variable for expression

var x = expr;


Iterating while boolean statement is 'true'

while (expr)


Yields value from iterator method

yield return expr;

Last modified: 11 February 2024