3

我的問題是完全一樣的。我想知道是否可以將日期或日期和時間插入到註釋中,而無需手動將其寫出。但是我真正想知道的是,有沒有辦法做到這一點,我將不得不用visual studio來實現一些東西來做到這一點,如果是這樣,我該怎麼做?任何幫助將不勝感激! :)
此外,我編碼C-夏普和正在使用Visual Studio 2010中在visual studio中,如何編寫將日期插入評論的宏?

+0

你會用什麼編程語言? – Zeddy 2013-03-17 22:58:26

+0

我目前正在使用C-Sharp。 – Jake 2013-03-17 22:59:31

回答

0

你既可以寫在Visual Studio宏或使用一些外部程序(如AutoHotKey)至的文本您。

-1

當有人張貼評論,你處理你的服務器端表單數據, 也許你會添加一個硬回車(
或CHR(13)),然後添加日期之前堅持的評論數據庫或XML文件。

所以你最終會喜歡的東西....

Comments == Comments + Strings.Chr(13) + System.DateTime.Today 

Comments == Comments + ("<br />") + System.DateTime.Today 
+1

我認爲OP正在尋找一個Visual Studio宏,以便在添加評論時將日期插入到他們的C#源代碼中。 – 2013-03-18 07:35:38

+0

啊好吧沃爾特感謝您的解釋 – Zeddy 2013-03-18 13:36:07

2

在Visual Studio 2010中,您寫在Visual Basic宏,並將它們添加到宏資源管理器。然後在C#代碼編輯器中工作時調用宏。我將我最喜歡的宏綁定到組合鍵,所以我可以在需要時快速運行它們。

如果您對宏和Visual Studio宏編輯器不熟悉,請查看此鏈接。 MSDN docs for Macros

這裏是爲您的C#代碼添加註釋和日期的代碼。

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#文件中的結果。

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