bard83 / csharpextensions

C# Extensions for Visual Studio Code
MIT License
2 stars 1 forks source link

Customized version of https://github.com/jchannon/csharpextensions -> https://github.com/KreativJos/csharpextensions -> https://github.com/bard83/csharpextensions

C# Extensions

Welcome to C# Extensions. This VSCode extension provides extensions to the IDE that will hopefully speed up your development workflow. It can currently be found at:

Features

Add C# Class

Add C# Class

Add C# Enum

Add C# Enum

Add C# Interface

Add C# Interface

Add constructor from properties

Add constructor from properties

Add body expression constructor from properties

Add body expression constructor from properties

This extension traverses up the folder tree to find the project.json or *.csproj and uses that as the parent folder to determine namespaces.

Custom Templates

Definition

The custom template must be defined in the vscode settings.json file. Access to File->Preference->Settings, Explode the Extensions section and select C# Extension then click on edit in settings.json .In the new section csharpextensions.templates must define the list of items which contain the custom templates. An item template is defined like below:

{
    "name": "MyCustomTemplate",
    "visibility": "public",
    "construct": "class",
    "description": "My awesome c# template",
    "header": "using System;\nusing System.Runtime.Serialization;\nusing System.Text.Json;",
    "attributes": [
        "DbContext(typeof(AppDbContext))",
        "Migration(\"${classname}\")"
    ],
    "genericsDefinition": "I,J,K",
    "declaration": "ISerializable, IEquatable",
    "genericsWhereClauses": [
        "where I : class",
        "where J : struct",
        "where K : IMyInterface",
    ],
    "body": "public void MyFancyMethod(string variable)\n{\n    System.Console.WriteLine(\"Hello World\");\n}"
}

visibility C# component visibility (public, private and etc...);

construct actually supported class, interface and struct;

header is used to group all the necessary usings module. Each using must be separated by a ;. The keyword using or the new line \n can be omitted. "using System;\nusing System.Runtime.Serialization;\nusing System.Text.Json;" and "System;System.Runtime.Serialization;System.Text.Json" produce the same output. Implicit usings rules will be applied.

genericsDefinition used to specify the generics for the construct automatically enclosed between <>;

declaration used to append all the necessary extended or implemented class or interface. The colon before the declaration will be automatically added. It could be used to add also generic clauses.

attributes used to specify the attributes for the construct. The attributes must be specified in a list of string. Using the placeholder ${classname} the construct name will be replaced instead.

genericsWhereClauses used to define the generics where clauses inside the custom template.

body body of template. It might be whatever C# code. The placeholder ${classname} gets replaced with the file name if it's defined.

Please note that the code defined inside the custom template should be valid C# code. This extension does not perform any validation on it.

Add new custom template

Add new custom template


Licence

MIT

See licence.txt

Legacy Repositories: