Need help with resharper-postfix?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

controlflow
127 Stars 11 Forks MIT License 519 Commits 28 Opened issues

Description

ReSharper Postfix Templates plugin

Services available

!
?

Need anything else?

Contributors list

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.

Demo

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

Features

Available templates:

  • .if
    – checks boolean expression to be true
    if (expr)
  • .else
    – checks boolean expression to be false
    if (!expr)
  • .null
    – checks nullable expression to be null
    if (expr == null)
  • .notnull
    – checks expression to be non-null
    if (expr != null)
  • .not
    – negates value of inner boolean expression
    !expr
  • .foreach
    – iterates over collection
    foreach (var x in expr)
  • .for
    – surrounds with loop
    for (var i = 0; i < expr.Length; i++)
  • .forr
    – reverse loop
    for (var i = expr.Length - 1; i >= 0; i--)
  • .var
    – initialize new variable with expression
    var x = expr;
  • .arg
    – helps surround argument with invocation
    Method(expr)
  • .to
    – assigns expression to some variable
    lvalue = expr;
  • .await
    – awaits expression with C# await keyword
    await expr
  • .cast
    – surrounds expression with cast
    ((SomeType) expr)
  • .field
    – intoduces field for expression
    _field = expr;
  • .prop
    – introduces property for expression
    Prop = expr;
  • .new
    – produces instantiation expression for type
    new T()
  • .par
    – surrounds outer expression with parentheses
    (expr)
  • .parse
    – parses string as value of some type
    int.Parse(expr)
  • .return
    – returns value from method/property
    return expr;
  • .typeof
    – wraps type usage with typeof-expression
    typeof(TExpr)
  • .switch
    – produces switch over integral/string type
    switch (expr)
  • .yield
    – yields value from iterator method
    yield return expr;
  • .throw
    – throws value of Exception type
    throw expr;
  • .using
    – surrounds disposable expression
    using (var x = expr)
  • .while
    – uses expression as loop condition
    while (expr)
  • .lock
    – surrounds expression with statement
    lock (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:

Static members completion

Enum members are available over values of enumeration types to produce equality/flag checks:

Enum members completion

Length/Count code completion solves one of the most common mistypings when dealing with arrays or collections:

Length/Count completion

Create type parameter from usage helps declaring generic methods in a postfix way:

Type parameter completion

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: options
  • 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).

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.