在Visual Studio中,如何编写将日期插入评论的宏? [英] In visual studio, how can I write a macro that will insert the date into a comment?

查看:107
本文介绍了在Visual Studio中,如何编写将日期插入评论的宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是确切的.我想知道是否有可能将日期或日期和时间插入注释中而不必手动将其写出.但是我真正想知道的是,有什么办法可以做到这一点,我是否必须在Visual Studio中实现某些功能才能为我做到这一点,如果可以的话,我该如何做到这一点?任何帮助将不胜感激! :)
另外,我正在使用C-Sharp进行编码,并且正在使用Visual Studio 2010.

My question is as exact as it is. I am wondering if it would be possible to insert the date or the date and time into a comment without having to manually write it out. But what I would really like to know is, is there a way to do this and will I have to implement something with visual studio to do this for me and if so, how can I do this? Any help will be greatly appreciated! :)
Also, I am coding in C-Sharp and am using Visual Studio 2010.

推荐答案

在Visual Studio 2010中,您可以在Visual Basic中编写宏并将其添加到宏资源管理器"中.然后在使用C#代码编辑器时调用宏.我将自己喜欢的宏绑定到组合键,因此可以在需要时快速运行它们.

In Visual Studio 2010 you write macros in Visual Basic and add them to the Macro Explorer. Then call the macros while working in your C# code editor. I bind my favorite macros to key combinations, so I can quickly run them when needed.

如果您不熟悉宏,则可以使用Visual Studio宏编辑器查看此链接. 用于宏的MSDN文档

If you are new to macros and the Visual Studio Macro editor check out this link. MSDN docs for Macros

这是在C#代码中添加注释和日期的代码.

Here is the code to add a comment and date to your C# code.

 Public Sub AddCommentWithDate()
    Dim doc As Document = DTE.ActiveDocument
    ' only modify the doc, if it is a text document in VS
    Dim textDoc As TextDocument = _
       CType(doc.Object("TextDocument"), TextDocument)

    ' verify that the code editor is C#
    If doc.ProjectItem.ContainingProject.Kind = _
       VSLangProj.PrjKind.prjKindCSharpProject Then
        textDoc.StartPoint.CreateEditPoint()
        textDoc.Selection.Insert("// A comment " & Date.Now)
    End If
End Sub

这是C#文件中的结果.

Here's the results in a C# file.

// A comment 3/18/2013 2:13:38 AM

这篇关于在Visual Studio中,如何编写将日期插入评论的宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆