C implements a way to automatically add copyright comment information to class and function code
- 2020-09-28 09:06:14
- OfStack
This article illustrates how C# automatically adds copyright annotation information to class and function code. It is Shared for your reference. The specific methods are as follows:
Take web project as an example:
1: Annotate the class
1. Under the installation path of visual studio
Such as: [is] : / Program files/Microsoft Visual Studio 8 / Common7 IDE/ItemTemplates/web cshare / 2052 / class zip, will the class inside. cs instead:
/*----------------------------------------------------------------
// All rights reserved.
//
// The file name:
// File function description:
//
//
// Create an identity:
//
// Modify logo:
// Modification description:
//
// Modify logo:
// Modification description:
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// $safeitemrootname$ Summary description of
/// </summary>
public class $safeitemrootname$
{
public $safeitemrootname$()
{
//
// TODO: Add the constructor logic here
//
}
}
/*----------------------------------------------------------------
// All rights reserved.
//
// The file name:
// File function description:
//
//
// Create an identity:
//
// Modify logo:
// Modification description:
//
// Modify logo:
// Modification description:
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// $safeitemrootname$ Summary description of
/// </summary>
public class $safeitemrootname$
{
public $safeitemrootname$()
{
//
// TODO: Add the constructor logic here
//
}
}
Just save the file (unzip first, then modify)
2:VS macro script adds function comment templates
Now the IDE is getting stronger and stronger, saving me a lot of time for the lazy. In order to use future code that you or others can understand, comments are essential. When you add comments to a function, the format is fixed. Writing each function once, or copying it from another function, is cumbersome and error-prone. This repetitive work is so annoying that you don't want to write notes, and VS's macro eliminates the "dirty, messy, tired" physical work.
Look 1, vs2010 macro script is VBScript, easy to use. I wrote a macro script to generate a function comment template, it is easier to see the code:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Sub AddFunComment()
Dim DocSel As EnvDTE.TextSelection
DocSel = DTE.ActiveDocument.Selection
DocSel.NewLine()
DocSel.Text = "/*******************************************************************"
DocSel.NewLine()
DocSel.Text = "* Function name: "
DocSel.NewLine()
DocSel.Text = "* work To: "
DocSel.NewLine()
DocSel.Text = "* ginseng The number: "
DocSel.NewLine()
DocSel.Text = "* return Back to the Value: "
DocSel.NewLine()
DocSel.Text = "* As a Re: Lonkil"
DocSel.NewLine()
DocSel.Text = "* Email address: lonkil{AT}gmail.com ( {AT} -> @ )"
DocSel.NewLine()
DocSel.Text = "* Date created: " + System.DateTime.Now.ToLongDateString()
DocSel.NewLine()
DocSel.Text = "*******************************************************************/"
End Sub
End Module
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Sub AddFunComment()
Dim DocSel As EnvDTE.TextSelection
DocSel = DTE.ActiveDocument.Selection
DocSel.NewLine()
DocSel.Text = "/*******************************************************************"
DocSel.NewLine()
DocSel.Text = "* Function name: "
DocSel.NewLine()
DocSel.Text = "* work To: "
DocSel.NewLine()
DocSel.Text = "* ginseng The number: "
DocSel.NewLine()
DocSel.Text = "* return Back to the Value: "
DocSel.NewLine()
DocSel.Text = "* As a Re: Lonkil"
DocSel.NewLine()
DocSel.Text = "* Email address: lonkil{AT}gmail.com ( {AT} -> @ )"
DocSel.NewLine()
DocSel.Text = "* Date created: " + System.DateTime.Now.ToLongDateString()
DocSel.NewLine()
DocSel.Text = "*******************************************************************/"
End Sub
End Module
Specific creation steps: vs2010 IDE - > Tools - > The macro - > Create a new macro project and select the location to save. Then copy the above script in and save it.
How to use it: Macro binding shortcut, vs2010 IDE -, written for you > Tools - > Options - > Select Keyboard - in the list on the left > On the right, in Show Command Include, select You create macro - > Position the cursor at "Press shortcut key" - > Type in a shortcut you want to name, such as "Alt+C", and save.
There is one point to note: Visual Studio 2005 Team Suite needs to be patched with SP1. Macro can only be used otherwise it will be invalid.
I believe that this article has a certain reference value for your C# programming.