Skip to content

Commit

Permalink
fix: fix error parsing platform and configuration
Browse files Browse the repository at this point in the history
because they can be any value and should not be an enum

Closes #21
  • Loading branch information
wgnf committed Aug 23, 2023
1 parent 926ffbf commit e13f8f0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 92 deletions.
24 changes: 12 additions & 12 deletions src/SlnParser.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(0)
.Configuration
.Should()
.Be(BuildConfiguration.Debug);
.Be(BuildConfigurationDefaults.Debug);

solution
.ConfigurationPlatforms
.ElementAt(0)
.Platform
.Should()
.Be(BuildPlatform.AnyCpu);
.Be(BuildPlatformDefaults.AnyCpu);

solution
.ConfigurationPlatforms
Expand All @@ -85,14 +85,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(1)
.Configuration
.Should()
.Be(BuildConfiguration.Debug);
.Be(BuildConfigurationDefaults.Debug);

solution
.ConfigurationPlatforms
.ElementAt(1)
.Platform
.Should()
.Be(BuildPlatform.X64);
.Be(BuildPlatformDefaults.X64);

solution
.ConfigurationPlatforms
Expand All @@ -106,14 +106,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(2)
.Configuration
.Should()
.Be(BuildConfiguration.Debug);
.Be(BuildConfigurationDefaults.Debug);

solution
.ConfigurationPlatforms
.ElementAt(2)
.Platform
.Should()
.Be(BuildPlatform.X86);
.Be(BuildPlatformDefaults.X86);

solution
.ConfigurationPlatforms
Expand All @@ -127,14 +127,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(3)
.Configuration
.Should()
.Be(BuildConfiguration.Release);
.Be(BuildConfigurationDefaults.Release);

solution
.ConfigurationPlatforms
.ElementAt(3)
.Platform
.Should()
.Be(BuildPlatform.AnyCpu);
.Be(BuildPlatformDefaults.AnyCpu);

solution
.ConfigurationPlatforms
Expand All @@ -148,14 +148,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(4)
.Configuration
.Should()
.Be(BuildConfiguration.Release);
.Be(BuildConfigurationDefaults.Release);

solution
.ConfigurationPlatforms
.ElementAt(4)
.Platform
.Should()
.Be(BuildPlatform.X64);
.Be(BuildPlatformDefaults.X64);

solution
.ConfigurationPlatforms
Expand All @@ -169,14 +169,14 @@ public void Should_Be_Able_To_Parse_SlnParser_Solution_Correctly()
.ElementAt(5)
.Configuration
.Should()
.Be(BuildConfiguration.Release);
.Be(BuildConfigurationDefaults.Release);

solution
.ConfigurationPlatforms
.ElementAt(5)
.Platform
.Should()
.Be(BuildPlatform.X86);
.Be(BuildPlatformDefaults.X86);

// -- Projects
solution
Expand Down
19 changes: 0 additions & 19 deletions src/SlnParser/Contracts/BuildConfiguration.cs

This file was deleted.

23 changes: 23 additions & 0 deletions src/SlnParser/Contracts/BuildConfigurationDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SlnParser.Contracts
{
/// <summary>
/// Common build-configuration defaults
/// </summary>
public static class BuildConfigurationDefaults
{
/// <summary>
/// The debug configuration
/// </summary>
public const string Debug = "Debug";

/// <summary>
/// The release configuration
/// </summary>
public const string Release = "Release";

/// <summary>
/// The default configuration
/// </summary>
public const string Default = "Default";
}
}
23 changes: 0 additions & 23 deletions src/SlnParser/Contracts/BuildPlatform.cs

This file was deleted.

38 changes: 38 additions & 0 deletions src/SlnParser/Contracts/BuildPlatformDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace SlnParser.Contracts
{
/// <summary>
/// Common build-platforms defaults
/// </summary>
public static class BuildPlatformDefaults
{
/// <summary>
/// Any CPU-platform is targeted
/// </summary>
public const string AnyCpu = "Any CPU";

/// <summary>
/// Only x64 (64 bit) CPU-platforms are targeted
/// </summary>
public const string X64 = "x64";

/// <summary>
/// Only x86 (32 bit) CPU-platforms are targeted
/// </summary>
public const string X86 = "x86";

/// <summary>
/// There is a mix of different platforms that are targeted
/// </summary>
public const string MixedPlatforms = "Mixed Platforms";

/// <summary>
/// Only Windows 32 platforms are targeted
/// </summary>
public const string Win32 = "Win32";

/// <summary>
/// Only Windows 7 platforms are targeted
/// </summary>
public const string Win7 = "Win7";
}
}
19 changes: 9 additions & 10 deletions src/SlnParser/Contracts/ConfigurationPlatform.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
namespace SlnParser.Contracts
{
/// <summary>
/// A Configuration of a Solution or Project describing which <see cref="BuildConfiguration" /> and
/// <see cref="BuildPlatform" /> is targeted
/// A Configuration of a Solution or Project describing which configuration and build-platform is targeted
/// </summary>
public class ConfigurationPlatform
{
/// <summary>
/// Create a new instance of <see cref="ConfigurationPlatform" />
/// </summary>
/// <param name="name">The name of the <see cref="ConfigurationPlatform" /></param>
/// <param name="configuration">The <see cref="BuildConfiguration" /> of the <see cref="ConfigurationPlatform" /></param>
/// <param name="platform">The <see cref="BuildPlatform" /> of the <see cref="ConfigurationPlatform" /></param>
/// <param name="configuration">The configuration of the <see cref="ConfigurationPlatform" /></param>
/// <param name="platform">The build-platform of the <see cref="ConfigurationPlatform" /></param>
public ConfigurationPlatform(
string name,
BuildConfiguration configuration,
BuildPlatform platform)
string configuration,
string platform)
{
Name = name;
Configuration = configuration;
Expand All @@ -28,13 +27,13 @@ public ConfigurationPlatform(
public string Name { get; }

/// <summary>
/// The <see cref="BuildConfiguration" /> the <see cref="ConfigurationPlatform" /> is targeting
/// The configuration the <see cref="ConfigurationPlatform" /> is targeting
/// </summary>
public BuildConfiguration Configuration { get; }
public string Configuration { get; }

/// <summary>
/// The <see cref="BuildPlatform" /> the <see cref="ConfigurationPlatform" /> is targeting
/// The build-platform the <see cref="ConfigurationPlatform" /> is targeting
/// </summary>
public BuildPlatform Platform { get; }
public string Platform { get; }
}
}
30 changes: 2 additions & 28 deletions src/SlnParser/Helper/SolutionConfigurationPlatformParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,40 +78,14 @@ private static ProjectConfigurationPlatform ParseConfigurationPlatform(string li
private static ConfigurationPlatform ParseConfigurationPlatformFromMatch(Match match)
{
var configurationName = match.Groups["name"].Value;
var buildConfigurationString = match.Groups["buildConfiguration"].Value;
var buildPlatformString = match.Groups["buildPlatform"].Value;

var buildConfiguration = ParseBuildConfiguration(buildConfigurationString);
var buildPlatform = ParseBuildPlatform(buildPlatformString);
var buildConfiguration = match.Groups["buildConfiguration"].Value;
var buildPlatform = match.Groups["buildPlatform"].Value;

var configurationPlatform = new ConfigurationPlatform(
configurationName,
buildConfiguration,
buildPlatform);
return configurationPlatform;
}

private static BuildConfiguration ParseBuildConfiguration(string buildConfigurationString)
{
return buildConfigurationString switch
{
"Debug" => BuildConfiguration.Debug,
"Release" => BuildConfiguration.Release,
_ => throw new UnexpectedSolutionStructureException(
$"{buildConfigurationString} is not recognized as a possible value for {nameof(BuildConfiguration)}")
};
}

private static BuildPlatform ParseBuildPlatform(string buildPlatformString)
{
return buildPlatformString switch
{
"Any CPU" => BuildPlatform.AnyCpu,
"x64" => BuildPlatform.X64,
"x86" => BuildPlatform.X86,
_ => throw new UnexpectedSolutionStructureException(
$"{buildPlatformString} is not recognized as a possible value for {nameof(BuildPlatform)}")
};
}
}
}

0 comments on commit e13f8f0

Please sign in to comment.