-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from SenDevGmbH/support-variables-in-versions
Added support for variables in versions
- Loading branch information
Showing
4 changed files
with
91 additions
and
12 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
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,57 @@ | ||
using NuGet.Versioning; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CentralisedPackageConverter | ||
{ | ||
public class PackageVersion | ||
{ | ||
|
||
public string? VariableName { get; private set; } | ||
|
||
public NuGetVersion? NuGetVersion { get; private set; } | ||
|
||
|
||
public static PackageVersion Parse(string value) | ||
{ | ||
if (!TryParse(value, out var version)) | ||
throw new ArgumentException("Invalid package version", nameof(value)); | ||
|
||
return version!; | ||
} | ||
public static bool TryParse(string value, out PackageVersion? version) | ||
{ | ||
|
||
if (value != null) | ||
{ | ||
if (value.Contains("$(")) | ||
{ | ||
version = new PackageVersion | ||
{ | ||
VariableName = value | ||
}; | ||
return true; | ||
} | ||
|
||
if (NuGetVersion.TryParse(value, out var nugetVersion)) | ||
{ | ||
version = new PackageVersion | ||
{ | ||
NuGetVersion = nugetVersion | ||
}; | ||
return true; | ||
} | ||
} | ||
version = null; | ||
return false; | ||
} | ||
|
||
public bool IsVariable => !string.IsNullOrWhiteSpace(VariableName); | ||
public string ToFullString() => NuGetVersion?.ToFullString() ?? VariableName ?? string.Empty; | ||
|
||
public override string ToString() => NuGetVersion?.ToString() ?? VariableName ?? string.Empty; | ||
} | ||
} |
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