Is there any extension for VS copying code position?

前端 未结 1 1793
时光取名叫无心
时光取名叫无心 2020-12-02 00:23

I want to copy code position with namespace, function name, class name, line number etc. I will paste this values to team project for task/bug entry.

相关标签:
1条回答
  • 2020-12-02 01:24

    You can use Visual Studio code model and Visual Commander to copy exactly what you need. For example, the following command copies file, line and namespace.class.function:

    EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
    if (ts == null)
      return;
    EnvDTE.CodeFunction func = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementFunction]
                as EnvDTE.CodeFunction;
    if (func == null)
      return;
    
    string result = DTE.ActiveWindow.Document.FullName + System.Environment.NewLine +
      "Line " + ts.CurrentLine + System.Environment.NewLine +
      func.FullName;
    System.Windows.Clipboard.SetText(result);
    

    Result:

    C:\Users\sv\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication3\Program.cs
    Line 12
    ConsoleApplication3.Program.Main
    
    0 讨论(0)
提交回复
热议问题