Automatically Add Comment Header to Source Files

J

jonfroehlich

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
 
R

rossum

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
As a student you lack both money and programming experience. Why not
solve both problems by writing the program you need for yourself? You
might even get your instructor to accept it as a term project or for
extra credit.

rossum
 
D

DeveloperX

As a student you lack both money and programming experience. Why not
solve both problems by writing the program you need for yourself? You
might even get your instructor to accept it as a term project or for
extra credit.

rossum

It's not a bad idea. MZ-Tools (My favourite add in ever) can add
comments and headers and so forth and is pretty cheap, but In relation
to Rossum's suggestion the web site has lots of resources for creating
your own add ins.

http://www.mztools.com/index.htm

and

http://www.mztools.com/resources_addin_developers.htm
 
O

Otis Mukinfus

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top