-
Notifications
You must be signed in to change notification settings - Fork 1
/
Project.cs
87 lines (75 loc) · 2.63 KB
/
Project.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vscmd {
partial class VisualStudio {
IEnumerable<dynamic> ProjectObjectsRecursive() {
foreach (var item in this.Solution.Projects) {
foreach (var project in ProjectObjectsFromItem(item))
yield return project;
}
}
static IEnumerable<dynamic> ProjectObjectsFromItem(dynamic item, int level = 0) {
//Console.WriteLine(new string(' ', level * 4) + item.Name + "=" + item.Kind);
if (item.ConfigurationManager != null) {
yield return item;
yield break;
}
var projectItems = item.ProjectItems;
if (projectItems != null) {
foreach (var projectItem in projectItems) {
var subProjectItem = projectItem.SubProject;
if (subProjectItem != null) {
foreach (var subProject in ProjectObjectsFromItem(subProjectItem, level + 1))
yield return subProject;
}
}
}
}
Project ProjectByName(string name) {
foreach (var item in this.ProjectObjectsRecursive()) {
if (name == item.Name)
return Project.FromObject(item);
}
throw new KeyNotFoundException(name);
}
string StartupProjectName {
get { return this.Solution.Properties.Item("StartupProject").Value; }
}
public Project StartupProject {
get { return this.ProjectByName(this.StartupProjectName); }
}
public partial class Project : ComObject {
protected Project(object project)
: base(project) { }
internal static Project FromObject(dynamic project) {
switch ((string)project.Kind) {
case "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}":
return new CPlusPlusProject(project);
case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}":
return new CSharpProject(project);
default:
return new Project(project);
}
}
public string Name { get { return this.Object.Name; } }
public dynamic Configuration(string name) {
return this.Object.Object.Configurations[name];
}
internal NotSupportedException KindNotSupportedException() {
return new NotSupportedException(string.Format(
"The operation is not suuported for this project type {0}.", this.Object.Kind));
}
}
partial class CPlusPlusProject : Project {
internal CPlusPlusProject(object project)
: base(project) { }
}
partial class CSharpProject : Project {
internal CSharpProject(object project)
: base(project) { }
}
}
}