5

I am trying to create a small custom snippet for my C# code in VS2010. It basically inserts a comment block for informational purposes. Within this code though I want the current date to be automatically inserted when the snippet is inserted.

Here is the current snippet I have:

<CodeSnippet Format="1.0.0">
    <Header>
        <Title>
            C# Class Comments
        </Title>
        <Shortcut>ccom</Shortcut>
    </Header>
    <Snippet>
        <Declarations>
            <Object>
                <ID>DateTime</ID>
                <Type>System.DateTime</Type>
                <Function>DateTime.Now()</Function>
            </Object>
            <Literal>
                <ID>Author</ID>
                <ToolTip>Replace with name creator of class.</ToolTip>
                <Default>"Author name"</Default>
            </Literal>
            <Literal>
                <ID>Date</ID>
                <ToolTip>Replace with date class was created</ToolTip>
                <Default>"Date"</Default>
            </Literal>
            <Literal>
                <ID>Modified</ID>
                <ToolTip>Replace with modified date of class</ToolTip>
                <Default>"Modified"</Default>
            </Literal>
            <Literal>
                <ID>Description</ID>
                <ToolTip>Replace with a short description of what the class is used for</ToolTip>
                <Default>"Description"</Default>
            </Literal>
        </Declarations>
        <Code Language="CSharp">
            <![CDATA[
            //*******************************************************************************;
            // Author:          $Author$
            // Created Date:    $DateTime$
            // Modified Date:   $Modified$
            // Description:     $Description$
            //*******************************************************************************;
            ]]>
        </Code>
    </Snippet>
</CodeSnippet>

What do I have to do to insert the date that the snippet was inserted into the code?

1
  • That's not possible. You'd need a macro instead. Commented Jan 28, 2012 at 21:09

1 Answer 1

9

This is unfortunately not really possible. The Visual Studio snippet architecture doesn't support replacement macros for items such as the current date / time

Sign up to request clarification or add additional context in comments.

1 Comment

Oh ok, because I saw something about functions but didn't quite know how to use them and thought that that would work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.