I am looking for a Visual Studio plugin or macro to manage comment
headers in my .cs files (e.g., for copyright and/or open source
license information). I realize that I could edit the template
Class.cs file in %Program Files%\Microsoft Visual Studio 8\Common7\IDE
\ItemTemplates\CSharp\1033\Class.zip; however, this would only work
for classes I create from now on.
I believe there are commercial programs out there that do this (e.g.,
Fast Formatter from
http://www.elegancetech.com/FF.aspx) but this is a
bit heavyweight for my needs and, as a student, I'd prefer free/open
source tools if possible.
j
Make a new folder under Macros and copy this into it.
'Put a file header at the cursor position
Sub FileHeader()
Dim doc As Document
Dim docName As String
' Get the name of this object from the file name
doc = DTE.ActiveDocument
docName = doc.Name 'get the name of the current document
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Text = "/* *"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text =
"============================================================================="
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Copyright © " & Date.Today & ", Your
Name"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text =
"============================================================================="
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "File Name:"
DTE.ActiveDocument.Selection.Indent(5)
DTE.ActiveDocument.Selection.Text = docName
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Programmer:"
DTE.ActiveDocument.Selection.Indent(4)
DTE.ActiveDocument.Selection.Text = "Tom Childers"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Creation Date:"
DTE.ActiveDocument.Selection.Indent(3)
DTE.ActiveDocument.Selection.Text = Date.Today
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text =
"============================================================================="
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Description:"
DTE.ActiveDocument.Selection.Indent(4)
DTE.ActiveDocument.Selection.Text = "DESCRIPTION"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text =
"============================================================================="
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "Modification Date:"
DTE.ActiveDocument.Selection.Indent()
DTE.ActiveDocument.Selection.Text = "MODDATE"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text =
"============================================================================="
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "*/"
End Sub
Good luck with your project,
Otis Mukinfus
http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com