Macros for multiline comments in Visual Studio

In my previous post I tried using code snippet to handle multiline comments insertion, but I didn't achieve removing those comments.

What I want to achieve is something like the default behavior for xml files when using the comment and uncomment buttons.

Using macros I can get it! So one macro to put comment (modified from the sample macro in vs) and one to uncomment.

The first surround the start and end selection with comment markers (for c# /* */).

The second takes the caret position and strips the previous start comment marker (/*) and the following end comment marker (*/)

It handles /*  */ and <!-- --> tags. Not VB (yet?)

You can associate this macro with a couple of button (or replace the default ones) and that's it.

Hope this helps someone

Code snippet for multiline comments in Visual Studio

Sometime you want to comment multiple line of c# code.

Visual studio uses // for each line of code if you use the comment/uncomment button.

I wanted to use the multiline comments /* */.

With the following snippet you can do this by using "Surround with"

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Multiline C# comment</Title>
            <Shortcut>comment</Shortcut>
            <Description>Code snippet for multiline C# comments</Description>
            <Author>Carlo Folini</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>name</ID>
                    <ToolTip>Multiline C# comment</ToolTip>
                    <Default></Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[/*$selected$*/]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Following this post, I put this snippet under My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets.

Didn't find a way to strip the comments tags, anyway

that's it

«dicembre»
domlunmarmergiovensab
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345