Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any extension for VS copying code position?

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.

like image 657
mkysoft Avatar asked Sep 10 '15 13:09

mkysoft


1 Answers

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
like image 137
Sergey Vlasov Avatar answered Nov 10 '22 21:11

Sergey Vlasov