ReSharper Postfix Templates plugin
The basic idea is to prevent caret jumps backwards while typing C# code. Kind of surround templates on steroids baked with code completion.
ReSharper 10
I'm excited to announce that this plugin is now integral part of ReSharper 10!
Further Postfix Templates development happens inside ReSharper codebase, so this repository is no longer maintained and intended to use as a source of code examples for ReSharper plugin development.
Download
- ReSharper versions currently supported by plugin are
9.1
and9.2
; - This plugin is available for download in ReSharper extensions gallery;
- ReSharper
8.x
and9.0
is no longer supported, check extension manager for latest versions; - ReSharper
7.1
is no longer supported, last build is available here; - Plugin's changelog is here.
Features
Available templates:
.if
– checks boolean expression to be trueif (expr)
.else
– checks boolean expression to be falseif (!expr)
.null
– checks nullable expression to be nullif (expr == null)
.notnull
– checks expression to be non-nullif (expr != null)
.not
– negates value of inner boolean expression!expr
.foreach
– iterates over collectionforeach (var x in expr)
.for
– surrounds with loopfor (var i = 0; i < expr.Length; i++)
.forr
– reverse loopfor (var i = expr.Length - 1; i >= 0; i--)
.var
– initialize new variable with expressionvar x = expr;
.arg
– helps surround argument with invocationMethod(expr)
.to
– assigns expression to some variablelvalue = expr;
.await
– awaits expression with C# await keywordawait expr
.cast
– surrounds expression with cast((SomeType) expr)
.field
– intoduces field for expression_field = expr;
.prop
– introduces property for expressionProp = expr;
.new
– produces instantiation expression for typenew T()
.par
– surrounds outer expression with parentheses(expr)
.parse
– parses string as value of some typeint.Parse(expr)
.return
– returns value from method/propertyreturn expr;
.typeof
– wraps type usage with typeof-expressiontypeof(TExpr)
.switch
– produces switch over integral/string typeswitch (expr)
.yield
– yields value from iterator methodyield return expr;
.throw
– throws value of Exception typethrow expr;
.using
– surrounds disposable expressionusing (var x = expr)
.while
– uses expression as loop conditionwhile (expr)
.lock
– surrounds expression with statementlock (expr)
.sel
– selects expression in editor
Also Postfix Templates including more C# code completion features sharing the same idea:
Static members of first argument type capatible available just like instance members:
Enum members are available over values of enumeration types to produce equality/flag checks:
Length/Count code completion solves one of the most common mistypings when dealing with arrays or collections:
Create type parameter from usage helps declaring generic methods in a postfix way:
Notes
- By now it supports only C# language (including C# in Razor markup)
- Templates can be expanded by
Tab
key just like ReSharper live templates - You can use ReSharper 8 double completion feature to list and invoke all the templates are not normally available in current context
- ReSharper 9.0 code completion filters can filter items introduced by postfix templates
- Options page allows to enable/disable specific templates and control braces insertion:
- You may also try out similar postfix completion feature in IntelliJ IDEA 14 (later supported in WebStorm 9 and PHPStorm 9)
Feedback
Feel free to post any issues or feature requests in YouTrack (use "PostfixCompletion" subsystem).