-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode_for_command
More file actions
95 lines (82 loc) · 2.93 KB
/
Code_for_command
File metadata and controls
95 lines (82 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using EnvDTE;
using EnvDTE80;
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.VisualStudio.Shell;
public class C : VisualCommanderExt.ICommand
{
public void Run(DTE2 DTE, Package package)
{
var debugger = DTE.Debugger;
var selectedProject = GetSelectedProject(DTE);
if (selectedProject != null)
{
var projectItems = GetProjectItems(selectedProject.ProjectItems);
foreach (var projectItem in projectItems)
{
// WriteToOutputWindow(DTE, string.Format("Processing project item: {0}", projectItem.Name));
if (projectItem.Name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
{
var fileCodeModel = projectItem.FileCodeModel;
if (fileCodeModel != null)
{
foreach (CodeElement codeElement in fileCodeModel.CodeElements)
{
AddBreakpointsToMethods(debugger, codeElement);
}
}
}
}
}
}
private Project GetSelectedProject(DTE2 DTE)
{
Array selectedItems = (Array)DTE.ToolWindows.SolutionExplorer.SelectedItems;
if (selectedItems.Length == 1)
{
UIHierarchyItem item = (UIHierarchyItem)selectedItems.GetValue(0);
return item.Object as Project;
}
return null;
}
private IEnumerable<ProjectItem> GetProjectItems(ProjectItems projectItems)
{
foreach (ProjectItem item in projectItems)
{
yield return item;
if (item.ProjectItems != null)
{
foreach (var childItem in GetProjectItems(item.ProjectItems))
{
yield return childItem;
}
}
}
}
private void AddBreakpointsToMethods(Debugger debugger, CodeElement codeElement)
{
if (codeElement.Kind == vsCMElement.vsCMElementNamespace || codeElement.Kind == vsCMElement.vsCMElementClass)
{
foreach (CodeElement member in codeElement.Children)
{
AddBreakpointsToMethods(debugger, member);
}
}
else if (codeElement.Kind == vsCMElement.vsCMElementFunction)
{
debugger.Breakpoints.Add(codeElement.FullName);
}
}
private void WriteToOutputWindow(DTE2 DTE, string message)
{
var outputWindow = DTE.ToolWindows.OutputWindow;
var outputPane = outputWindow.OutputWindowPanes.Cast<OutputWindowPane>().FirstOrDefault(p => p.Name == "General");
if (outputPane == null)
{
outputPane = outputWindow.OutputWindowPanes.Add("General");
}
outputPane.OutputString(message + Environment.NewLine);
outputPane.Activate(); // Optional: to bring the Output window to the front
}
}