12

I want to write a Visual Studio snippet which allows me to quickly create a class of the form:

public SomeClass
{
    public SomeType SomeProperty { get; private set; }
    public SomeClass(SomeType someProperty) { SomeProperty = someProperty; }
}

I want the parameter on the constructor to have the same name as the property, but lower-cased. I don't want to have to type the name twice. How do I do this?

I've already looked at the XML for snippets and I discovered that there are certain functions that can be used. For example, the built-in "switch" code snippet contains the following instruction:

<Function>GenerateSwitchCases($expression$)</Function>

According to this MSDN documentation page, there are three built-in functions that you can use in this <Function> tag. Unfortunately, neither of them does what I want (lower-case the first letter). Is it possible to define a function that I can then use in my snippet?

Timwi
  • 65,159
  • 33
  • 165
  • 230

1 Answers1

6

No this is not possible in Visual Studio today. The definition and execution of snippet functions is directly controlled by the C# language service. It is not currently an extensibility point. It is being considered for a future version of the product though.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Is it? Are you sure? There is a comment on a Microsoft Connect post that said this is considered "for the next version", but that comment is from 2005 and there have been two next versions since... – Timwi Feb 17 '10 at 14:54
  • For clarity, my comment was referring to your last sentence in which you claimed "It is being considered for a future version". I am unconvinced that this is the case. – Timwi Feb 23 '10 at 17:59
  • @Timwii, I can assure you it's actively being considered for a future version of the product. Like always no assurances can be made but it is something that we are investigating. – JaredPar Feb 23 '10 at 18:24
  • 1
    This post claims to have created such a custom function: http://stackoverflow.com/questions/12730156 – Daryl Oct 23 '15 at 19:11
  • 1
    @Daryl: OP says it won't work for C#. If you read the last couple of comments, he explains. – Shai Cohen Jan 22 '19 at 15:18