使用 vs2008 的宏 Macro 来实现一个小小的功能,向代码指定位置插入当前系统时间的值,“alt+F8”打开宏编辑器,输入你想输入的代码
Public Module Module1
Sub PrintDateTime()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert(DateTime.Now.ToString())
End If
End Sub
Sub PrintMyName()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("anders lu")
End If
End Sub
Sub PrintXMLAnnotation()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert("功 能:")
selection.NewLine()
selection.Insert("作 者: anders lu")
selection.NewLine()
selection.Insert("创建时间:" + DateTime.Now.ToString())
selection.NewLine()
selection.Insert("修正履历:")
selection.NewLine()
selection.Insert("修正时间:")
End If
End Sub
End Module这样在写代码的时候就可以使用它了,两步,第一步三个"/";第二步执行宏,结果如下:
/// <summary>
/// 功 能:
/// 作 者: anders lu
/// 创建时间:2011-8-5 17:43:22
/// 修正履历:
/// 修正时间:
/// </summary>
/// <typeparam name="Q"></typeparam>
/// <returns></returns>
我最近在使用代码段及代码模板在整理一些项目需要的东西,会陆续写成博客。。。。。