Repository navigation
Expand file tree
/
Copy pathSolutionUtilities.cs
More file actions
83 lines (67 loc) · 3.51 KB
/
Copy pathSolutionUtilities.cs
File metadata and controls
83 lines (67 loc) · 3.51 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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.UnitTests
{
public class SolutionUtilities
{
public static ProjectChanges GetSingleChangedProjectChanges(Solution oldSolution, Solution newSolution)
{
var solutionDifferences = newSolution.GetChanges(oldSolution);
var projectId = solutionDifferences.GetProjectChanges().Single().ProjectId;
var oldProject = oldSolution.GetProject(projectId);
var newProject = newSolution.GetProject(projectId);
return newProject.GetChanges(oldProject);
}
private static IEnumerable<ProjectChanges> GetChangedProjectChanges(Solution oldSolution, Solution newSolution)
{
var solutionDifferences = newSolution.GetChanges(oldSolution);
return solutionDifferences.GetProjectChanges().Select(n => n.NewProject.GetChanges(n.OldProject));
}
public static Document GetSingleChangedDocument(Solution oldSolution, Solution newSolution)
{
var projectDifferences = GetSingleChangedProjectChanges(oldSolution, newSolution);
var documentId = projectDifferences.GetChangedDocuments().Single();
return newSolution.GetDocument(documentId);
}
public static TextDocument GetSingleChangedAdditionalDocument(Solution oldSolution, Solution newSolution)
{
var projectDifferences = GetSingleChangedProjectChanges(oldSolution, newSolution);
var documentId = projectDifferences.GetChangedAdditionalDocuments().Single();
return newSolution.GetAdditionalDocument(documentId);
}
public static IEnumerable<DocumentId> GetChangedDocuments(Solution oldSolution, Solution newSolution)
{
var changedDocuments = new List<DocumentId>();
var projectsDifference = GetChangedProjectChanges(oldSolution, newSolution);
foreach (var projectDifference in projectsDifference)
{
changedDocuments.AddRange(projectDifference.GetChangedDocuments());
}
return changedDocuments;
}
public static Document GetSingleAddedDocument(Solution oldSolution, Solution newSolution)
{
var projectDifferences = GetSingleChangedProjectChanges(oldSolution, newSolution);
var documentId = projectDifferences.GetAddedDocuments().Single();
return newSolution.GetDocument(documentId);
}
public static IEnumerable<DocumentId> GetAddedDocuments(Solution oldSolution, Solution newSolution)
{
var addedDocuments = new List<DocumentId>();
var projectsDifference = GetChangedProjectChanges(oldSolution, newSolution);
foreach (var projectDifference in projectsDifference)
{
addedDocuments.AddRange(projectDifference.GetAddedDocuments());
}
return addedDocuments;
}
public static Tuple<Project, ProjectReference> GetSingleAddedProjectReference(Solution oldSolution, Solution newSolution)
{
var projectChanges = GetSingleChangedProjectChanges(oldSolution, newSolution);
return Tuple.Create(projectChanges.NewProject, projectChanges.GetAddedProjectReferences().Single());
}
}
}