VSCode Property Snippet With XML Doc Comments

Filed under: .NET

I wanted a way to make it easier to generate C# XML code comments for properties for Visual Studio Code ("VSCode"). Working with doc comments in VSCode is painful. There is no ghost-doc equivalent extension for C#.

The closest extension for generating comments is the docomment extension which is being replaced by omnisharp functionality.

If you run analyzers for code documentation; constructors, properties, and other public code fragments require specific phrases and required XML elements.

On windows, you can fall back to Visual Studio. If you’re running your dev-environment on Linux, using Visual Studio isn’t an option.

Visual Studio Code has documentation for user-defined code snippets.

I found a post on how to split camel-cased words into lower-cased fragments on stack overflow

Using the above, I was able to cobble together the snippets below.

    "prop": {
        "prefix": "prop",
        "body": [
            "/// <summary>Gets or sets the ${2/([A-Z][a-z]+$)|([A-Z][a-z]+)/${1:/downcase}${2:/downcase}${2:+ }/g}<summary>",
            "/// <value>Property <c>${2:property}</c> represents ${3:description}.</value>",
            "public ${1:type} ${2:Property} { get; set; }"
    "ctor-summary": {
        "prefix": "ctor-summary",
        "body": [
            "Initializes a new instance of the <see cref=\"$TM_FILENAME_BASE\"/> class."

I hope this helps.

Nerdy Mishka