My question is as exact as it is. I am wondering if it would be possible to insert the date or the date and time into a comment without having to manually write it out. But what I would really like to know is, is there a way to do this and will I have to implement something with visual studio to do this for me and if so, how can I do this? Any help will be greatly appreciated! :)
Also, I am coding in C-Sharp and am using Visual Studio 2010.

- 181
- 2
- 15
-
What programming language would you be using? – Zeddy Mar 17 '13 at 22:58
-
I am currently writing in C-Sharp. – Jake Mar 17 '13 at 22:59
3 Answers
In Visual Studio 2010 you write macros in Visual Basic and add them to the Macro Explorer. Then call the macros while working in your C# code editor. I bind my favorite macros to key combinations, so I can quickly run them when needed.
If you are new to macros and the Visual Studio Macro editor check out this link. MSDN docs for Macros
Here is the code to add a comment and date to your C# code.
Public Sub AddCommentWithDate()
Dim doc As Document = DTE.ActiveDocument
' only modify the doc, if it is a text document in VS
Dim textDoc As TextDocument = _
CType(doc.Object("TextDocument"), TextDocument)
' verify that the code editor is C#
If doc.ProjectItem.ContainingProject.Kind = _
VSLangProj.PrjKind.prjKindCSharpProject Then
textDoc.StartPoint.CreateEditPoint()
textDoc.Selection.Insert("// A comment " & Date.Now)
End If
End Sub
Here's the results in a C# file.
// A comment 3/18/2013 2:13:38 AM

- 6,977
- 1
- 28
- 35
You could either write a macro in Visual Studio or use some external program (such as AutoHotKey) to type the text for you.

- 19,940
- 10
- 72
- 93
When someone posts a comment and you process the form data on your serverside,
maybe you would add a hard return (
or chr(13)) and then add the date BEFORE persisting the comments to a database or xml file.
so you would end up with something like....
Comments == Comments + Strings.Chr(13) + System.DateTime.Today
or
Comments == Comments + ("<br />") + System.DateTime.Today

- 2,079
- 1
- 15
- 23
-
1I think the OP is looking for a Visual Studio macro to insert the date into their C# source code when they add a comment. – Walt Ritscher Mar 18 '13 at 07:35