2011-10-02 19 views
0

コードで問題を説明するときは、しばしばline/column/functionで参照する必要があります。 私のためにその情報をコピーするVisual Studioのマクロ/アドインはありますか?Visual Studioでのカーソル位置のクリップボードへの取得

それがクリップボードにコピーすることができれば、それは完璧になる:ファイル、行、列、関数名

しかし、私は任意の組み合わせを取ると思います:)。

ありがとうございます!

+0

ファイル - >新規 - >プロジェクト - >インストール済みテンプレート - >その他のプロジェクトタイプ - >拡張機能 - > Visual Studioアドイン。 3週間後には、新機能を欲しがることを後悔するでしょう:) – Gleno

+0

本当、そうです:)しかし、私は横行しないようにしていました。 – VitalyB

答えて

0

私はマクロをやりました。残念ながら、マクロからクリップボードにアクセスできませんでしたので、その部分にNirCmdを使用する必要がありました。それ以外は素晴らしいです!

Public Sub CopyLocation() 

    Dim fileName = DTE.ActiveDocument.Name 
    Dim line = "" 
    Dim column = "" 
    Dim functionName = "" 
    Dim className = "" 

    Dim textDocument = TryCast(DTE.ActiveDocument.Object, TextDocument) 
    If textDocument IsNot Nothing Then 

     Dim activePoint = textDocument.Selection.ActivePoint 

     column = activePoint.DisplayColumn 
     line = activePoint.Line 

     Dim codeElement As CodeElement 

     codeElement = activePoint.CodeElement(vsCMElement.vsCMElementFunction) 
     If codeElement IsNot Nothing Then 
      functionName = codeElement.Name 
     End If 

     codeElement = activePoint.CodeElement(vsCMElement.vsCMElementClass) 
     If codeElement IsNot Nothing Then 
      className = codeElement.Name 
     End If 

    End If 

    Dim output As String = String.Format("File: {0} ", fileName) 
    If (String.IsNullOrEmpty(line) = False) Then output = output & String.Format("Line: {0} ", line) 
    If (String.IsNullOrEmpty(column) = False) Then output = output & String.Format("Column: {0} ", column) 
    If (String.IsNullOrEmpty(className) = False) Then output = output & String.Format("at {0}", className) 
    If (String.IsNullOrEmpty(functionName) = False) Then output = output & String.Format(".{0}", functionName) 

    Dim process As System.Diagnostics.Process 
    process.Start("c:\NoInstall files\nircmd.exe", String.Format("clipboard set ""{0}""", output)) 

End Sub 
関連する問題