Vscode-powershell: snippit PSCustomObject

Created on 3 Feb 2018  路  3Comments  路  Source: PowerShell/vscode-powershell

Sorry I ask again to add a snippit..:-)
but Is it possible you add a snippit for PSCustomObject

e.g
[PSCustomObject]@{
Name = $Name
Description = $Description
Path = $Path
}

Or is there already a snippit for it?

thanx

Hackathon Up-for-Grabs

Most helpful comment

No such snippet exists atm. I'm not sure about the utility of the snippet as defined above since my PSCustomObject is very likely to have different fields than your PSCustomObject (Name, Description, Path). So the expansion wouldn't save me much if I had to delete most of it.

Perhaps the snippet could be tweaked to define a single name/value set of placeholders.

BTW you can pretty easily create your own custom snippets - see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets

This would give you a chance to experiment with the snippet and hone it.

All 3 comments

No such snippet exists atm. I'm not sure about the utility of the snippet as defined above since my PSCustomObject is very likely to have different fields than your PSCustomObject (Name, Description, Path). So the expansion wouldn't save me much if I had to delete most of it.

Perhaps the snippet could be tweaked to define a single name/value set of placeholders.

BTW you can pretty easily create your own custom snippets - see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets

This would give you a chance to experiment with the snippet and hone it.

ok very good point, thanks
I'll have a look at the userdefined snippits

something like this:

"PSCustomObject": {
    "prefix": "PSCustomObject",
    "body": [
        "[PSCustomObject]@{",
        "\t${1:Name} = ${2:Value}",
        "}"
    ],
    "description": "Creates a PSCustomObject"
}

and for hashtable

"Hashtable": {
    "prefix": "Hashtable",
    "body": [
        "\\$${1:Var} = @{",
        "\t${2:Name} = ${3:Value}",
        "}"
    ],
    "description": "Creates a Hashtable"
}

This will be just a matter of adding these snippets to:
https://github.com/PowerShell/vscode-powershell/blob/master/snippets/PowerShell.json

Was this page helpful?
0 / 5 - 0 ratings