Come forzare UpperCase in un frammento di VS2008?
-
20-09-2019 - |
Domanda
Ho optato per il seguente stile di creazione di proprietà (con un campo di supporto):
private _firstName;
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
Dato che il nome della proprietà è simile al nome del campo di supporto, ho migliorato il costruito nel prop
frammento al seguente:
<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prop</Title>
<Author>Frank Rizzo</Author>
<Description>Code snippet for property and backing field - changed one (not the original).</Description>
<Shortcut>prop</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[private $type$ _$field$;
public $type$ $field$
{
get { return _$field$;}
set { _$field$ = value;}
}
$end$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Questo funziona ad un grado, ma l'involucro del campo supporto e il nome della proprietà è sempre lo stesso, dove, come nel mio convenzione, il campo supporto è cammello carter, dove, come il nome della proprietà è pascal-cased.
Quindi la mia domanda è questa:? Non la sintassi frammento di avere un modo per cambiare la prima lettera della proprietà, in modo che il frammento potrebbe rispettare la mia convenzione
Soluzione
Purtroppo, questo non è possibile (ancora).
Si spera, sarà possibile in una futura versione di Visual Studio.
Altri suggerimenti
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Code File Header</Title>
<Author>Муся</Author>
<Shortcut>codehead</Shortcut>
<Description>Гавнокодец</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Name</ID>
<Default>Header</Default>
</Literal>
<Literal>
<ID>LowerName</ID>
<Default>header</Default>
</Literal>
<Literal>
<ID>Type</ID>
<Default>object</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
public $Type$ $Name$
{
get { return $LowerName$; }
set
{
$LowerName$ = value;
OnPropertyChanged("$Name$");
}
}
$Type$ $LowerName$;
]]>
</Code>
</Snippet>
</CodeSnippet>