I was wondering if anyone knows how you can make a Visual Studio snippet autoformat the input to a Literal shortcut field.
Say I want to create a snippet for a property. I want it the CDATA to look like:
private bool _$propertyName$;
private bool $propertyName$ { get { ... } set {...} }
so that when the user enters the $propertyName$
whilst calling the snippet he only has to fill in IsGrounded
and then have the outputted code look like this:
private bool _isGrounded;
private bool IsGrounded { get { ... } set {...} }
The only way I know of on how to do this is by having a seperate $backingField$
and $propertyName$
literals in my snippet declarations that the user would have to fill out seperately, like so:
private bool _$backingFieldName$;
private bool $propertyName$ { get { ... } set {...} }
Is that truly the only way? Then the user would have to fill in isGrounded
and IsGrounded
. I would rather have them enter $propertyName$
once and then autoformat that into isGrounded and IsGrounded in their respective fields.
Here is my current snippet code using the workaround I just talked about. Is it possible to reduce the amount of fields you need to fill in to just the access and property name shortcut fields?
I know about the existance of the default prop
and propfull
snippets, but they do not offer exactly what I want.
<Snippet>
<Code Language="CSharp">
<![CDATA[
private bool _$backingFieldName$;
$access1$ bool $propertyName$
{
$access2$ get
{
return _$backingFieldName$;
}
$access3$ set
{
_$backingFieldName$ = value;
}
}
]]>
</Code>
<Declarations>
<Literal>
<ID>backingFieldName</ID>
<ToolTip>The name for the backing field.</ToolTip>
<Default>name</Default>
</Literal>
<Literal>
<ID>propertyName</ID>
<ToolTip>The name for the property.</ToolTip>
<Default>Name</Default>
</Literal>
<Literal>
<ID>access1</ID>
<ToolTip>Access modifier for the property.</ToolTip>
<Default>private</Default>
</Literal>
<Literal>
<ID>access2</ID>
<ToolTip>Access modifier for the getter.</ToolTip>
<Default>private</Default>
</Literal>
<Literal>
<ID>access3</ID>
<ToolTip>Access modifier for the setter.</ToolTip>
<Default>private</Default>
</Literal>
</Declarations>
</Snippet>