Visual Studio snippets
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CSharp
JavaScript
LICENSE
README.md

README.md

Visual Studio snippets

C# Snippets

ArrangeActAssert

By typing a + TAB + TAB (or aaa + TAB for long) you end up with an empty failing test method.

// Arrange
$end$

// Act


// Assert
throw new NotImplementedException();

GuardClause (field)

I think that this is by far my favorite snippet.

If you define your field following the private readonly ISomeService _fieldName; and inject it in the controller like this public MyController(ISomeService fieldName){}, this snippet is for you!

public class MyClass
{
    private readonly ISomeService _fieldName;
    public MyClass(ISomeService fieldName){
        // Place your cursor here
    }
}

From there, copy (ctrl+c) fieldName, place your cursor in the constructor body and type g + TAB + TAB (or guard + TAB for long) then paste (ctrl+v). You should endup with the following in less than a second:

public class MyClass
{
    private readonly ISomeService _fieldName;
    public MyClass(ISomeService fieldName){
        _fieldName = fieldName ?? throw new ArgumentNullException(nameof(fieldName));
    }
}

The complete sequence (this should take ±2sec):

  1. dbl-click OR ctrl+click fieldName
  2. ctrl+c
  3. click inside the constructor body
  4. Type g
  5. Hit TAB twice
  6. ctrl+v
  7. ENTER

GuardClause (old)

Create a guard clause for an injected dependency.

if ($paramName$ == null) { throw new ArgumentNullException(nameof($paramName$)); }

GuardClause (property)

Create a guard clause for an injected dependency using the 2017 construct. This snippet offers two parameters: the property name and the parameter name.

$propName$ = $paramName$ ?? throw new ArgumentNullException(nameof($paramName$));

GuardClause (string)

Create a guard clause for an injected string dependency.

if (string.IsNullOrWhiteSpace($paramName$)) { throw new ArgumentNullException(nameof($paramName$)); }

ShouldBeTested

Create a failing XUnit test method named Should_be_tested. Shortcut: sbt.

[Fact]
public void Should_be_tested()
{
    throw new NotImplementedException();
}

JavaScript Snippets

JSModuleDomRdy

Allow to create a jQuery ready JavaScript module.

; (function ($, window, document, undefined) {
    "use strict"
    $(function () {
        // DOM READY CODE HERE...
        ~end~
    });
}(jQuery, window, document));