I have a code snippet structures like so:
private $type$ $lowercaseName$;
public $type$ $uppercaseName$
{
get { return $lowercaseName$; }
set { $lowercaseName$ = value; }
}
It generates stuff like:
private string randomValue;
public string RandomValue
{
get { return randomValue; }
set { randomValue = value; }
}
Thats a very oversimplified version... its really a lot more complicated... and its just that much more information to type in. It would be nice if you could type in $uppercaseName$
, and then a custom snippet function would assign a value to $lowercaseName$
....
But is it even possible to write custom snippet functions? I don't see anything about this in the documentation...
If it is possible... how?
It is not yet possible. See this suggestion for 2010 that was denied.
http://connect.microsoft.com/VisualStudio/feedback/details/523601/allow-custom-code-snippet-functions
It seems this feature was suggested when snippets were introduced, and has been re-suggested every version, and shot down saying they don't have enough time.
Rather than using the convention of having camelCase fields and PascalCase properties, I have adopted a convention of a using leading underscore for backing fields. The following code snippet works for me.
public $type$ $property$
{
get { return _$property$;}
set { _$property$ = value;}
}
private $type$ _$property$;
$end$
And in attempt to snub the "underscore is a prefix and prefixes are bad" holy war, I believ it to be more a convention than a prefix much like upper v. lower initial letters for properties v. parameters. Any use of a field with a leading underscore outside of it's associated property implementation should be code smell.
My answer is Resharper. Live Templates.
It is very annoying having this limitation, but like many other Visual Studio limitations, Resharper nails it. It is a performance hog, so I operate with the code analysis turned off. The speed is then acceptable, and live templates save a lot of time.
There are about twenty other good reasons to have a tool LIKE Resharper to make you a fantastic coder.
I can't write "hello world" without Resharper any more... and I can't debug it without Reflector =P
Also, go to the Extension Manager and click Online Gallery. Type "snippet" in the Search box, and there are a few tools there that look like they might help for free :). The extension gallery is pure productivity gold.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With