H. (冬) Tony

or any MACRO I can use to accomplish this when I insert a copyright code snippet into my code

ClassName() function can output the class name but I need to put copyright snippet at the top of the file, outside of any class so it doesn't work for me.

many thanks.



Re: Visual C# IDE any code snippet can use current Date and current file name?

Chris Brandsma

Snippet: no luck.

Resharper has a feature called File Templates that will create entire files from a user defined template. They also have macros for Current date, current time, etc. It would be easy to create a template that would automatically put the copyright text in any part of the file that you want.

Otherwise:
4 guys from Rolla has a good article on how to create a Macro.
http://aspnet.4guysfromrolla.com/articles/032305-1.aspx







Re: Visual C# IDE any code snippet can use current Date and current file name?

H. Tony

thanks, I have created a macro myself like following:

Code Snippet

Sub CopyRight()
Dim fileName As String
Dim editPoint As EnvDTE.EditPoint
Dim textDocument As EnvDTE.TextDocument
Dim DoubleEOL As String

fileName = DTE.ActiveDocument.Name
DoubleEOL = CStr(Microsoft.VisualBasic.Constants.vbNewLine) & CStr(Microsoft.VisualBasic.Constants.vbNewLine)

textDocument = DTE.ActiveDocument.Object("TextDocument")
editPoint = textDocument.CreateEditPoint()
editPoint.Insert("//------------------------------------------------------------------------" & _
DoubleEOL & _
...
"// File: " & _
fileName & _
DoubleEOL & _
"// Created On: " & _
System.DateTime.Now.ToString() & _
DoubleEOL & _
"// Author(s): H. Tony" & _
DoubleEOL & _
"//------------------------------------------------------------------------" & _
DoubleEOL)
End Sub


it's not perfect but it works. too bad code snippet doesn't support script, otherwise it would be a lot more useful.

will orcas change that





Re: Visual C# IDE any code snippet can use current Date and current file name?

Chris Brandsma

I haven't notices any changes to the snippets in Orcas as of yet. But I can't say I've been looking really hard yet.