Visual Studio code generation - Use uppercase type names

397 views Asked by At

I prefer to use actual type names for primitive types instead of their corresponding keywords, such as String instead of string, Int32 instead of int, etc., because I like to have consistent syntax highlight and casing - that is, typenames are colored like typenames (aqua blue), and cased properly (uppercase first letters).

How can I tell VS that whenever it generates any code (for example when I select "Implement interface" option on an interface name, or an automatically generated event handler and whatnot) it should add the typenames according to my liking?

1

There are 1 answers

0
PiotrWolkowski On BEST ANSWER

One option is for you to manually change the snippets you are interested in. In Visual Sutio (I'm using 2013 Community Edition) go to Tools -> Code Snippets Manager... (or hit Ctrl+K, Ctrl+B). You will get a dialog with all the snippets VS is using:

enter image description here

Select snippet you want to change. E.g. for loop in Visual C# section. You will get the location of the snippet. You can edit it. For example snippet declaration of the for loop:

<Snippet>
    <Declarations>
        <Literal>
            <ID>index</ID>
            <Default>i</Default>
            <ToolTip>Index</ToolTip>
        </Literal>
        <Literal>
            <ID>max</ID>
            <Default>length</Default>
            <ToolTip>Max length</ToolTip>
        </Literal>
    </Declarations>
    <Code Language="csharp"><![CDATA[for (int $index$ = 0; $index$ < $max$; $index$++)
    {
    $selected$ $end$
    }]]>
    </Code>
</Snippet>

To get what you want you have to replace for (int $index$ = 0; with for (Int32 $index$ = 0;

To change all the snippets is a laborious task but I bet in most cases you can use Notepad++ find and replace function (if you correctly and precisely define what have to be replaced) to replace aliases with proper type names.