-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement parsing of ProjectConfigurationPlatforms
Closes #7
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/SlnParser/Helper/EnrichSolutionWithProjectConfigurationPlatforms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using SlnParser.Contracts; | ||
using SlnParser.Contracts.Exceptions; | ||
using SlnParser.Contracts.Helper; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SlnParser.Helper | ||
{ | ||
internal sealed class EnrichSolutionWithProjectConfigurationPlatforms : IEnrichSolution | ||
{ | ||
private readonly IParseSolutionConfigurationPlatform _parseSolutionConfigurationPlatform; | ||
|
||
public EnrichSolutionWithProjectConfigurationPlatforms() | ||
{ | ||
_parseSolutionConfigurationPlatform = new SolutionConfigurationPlatformParser(); | ||
} | ||
|
||
public void Enrich(Solution solution, IEnumerable<string> fileContents) | ||
{ | ||
var projectConfigurations = _parseSolutionConfigurationPlatform.Parse( | ||
fileContents, | ||
"GlobalSection(ProjectConfiguration"); | ||
MapConfigurationPlatformsToProjects(solution, projectConfigurations); | ||
} | ||
|
||
private static void MapConfigurationPlatformsToProjects( | ||
Solution solution, | ||
IEnumerable<ProjectConfigurationPlatform> projectConfigurations) | ||
{ | ||
foreach (var configuration in projectConfigurations) | ||
MapConfigurationPlatformToProject(solution, configuration); | ||
} | ||
|
||
private static void MapConfigurationPlatformToProject( | ||
Solution solution, | ||
ProjectConfigurationPlatform configuration) | ||
{ | ||
if (!configuration.ProjectId.HasValue) | ||
throw new UnexpectedSolutionStructureException( | ||
"Expected to find a project-id " + | ||
$"for the Project-Platform-Configuration '{configuration.ConfigurationPlatform.Name}'"); | ||
|
||
var project = solution | ||
.AllProjects | ||
.FirstOrDefault(project => project.Id == configuration.ProjectId.Value); | ||
|
||
if (project == null) | ||
throw new UnexpectedSolutionStructureException( | ||
"Expected to find a project with the id " + | ||
$"'{configuration.ProjectId.Value}' for the Project-Platform-Configuration " + | ||
$"'{configuration.ConfigurationPlatform.Name}'"); | ||
|
||
if (!(project is SolutionProject solutionProject)) | ||
throw new UnexpectedSolutionStructureException( | ||
"Expected to find a Solution-Project with the id " + | ||
$"'{configuration.ProjectId.Value}' for the Project-Platform-Configuration " + | ||
$"'{configuration.ConfigurationPlatform.Name}' but found " + | ||
$" project of type '{project.GetType().Name}' instead"); | ||
|
||
solutionProject.AddConfigurationPlatform(configuration.ConfigurationPlatform); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters