-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Better search versions error experience #45144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,20 @@ namespace Microsoft.DotNet.Workloads.Workload | |
{ | ||
static class WorkloadSetVersion | ||
{ | ||
public static bool IsWorkloadSetPackageVersion(string workloadSetVersion) | ||
{ | ||
|
||
string[] sections = workloadSetVersion.Split(['-', '+'], 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first few lines here are duplicated from below, but they can't really be de-duped, as they are just defining variables. The variables would need to be defined either way. |
||
string versionCore = sections[0]; | ||
string? preReleaseOrBuild = sections.Length > 1 ? sections[1] : null; | ||
|
||
string[] coreComponents = versionCore.Split('.'); | ||
return coreComponents.Length >= 3 && coreComponents.Length <= 4; | ||
} | ||
|
||
public static string ToWorkloadSetPackageVersion(string workloadSetVersion, out SdkFeatureBand sdkFeatureBand) | ||
{ | ||
string[] sections = workloadSetVersion.Split(new char[] { '-', '+' }, 2); | ||
string[] sections = workloadSetVersion.Split(['-', '+'], 2); | ||
string versionCore = sections[0]; | ||
string? preReleaseOrBuild = sections.Length > 1 ? sections[1] : null; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deduplicated the code. Also, noticed private static string[] SeparateCoreComponents(string workloadSetVersion, out string[] sections)
{
sections = workloadSetVersion.Split(['-', '+'], 2);
return sections[0].Split('.');
}
public static bool IsWorkloadSetPackageVersion(string workloadSetVersion)
{
string[] coreComponents = SeparateCoreComponents(workloadSetVersion, out _);
return coreComponents.Length >= 3 && coreComponents.Length <= 4;
}
public static string ToWorkloadSetPackageVersion(string workloadSetVersion, out SdkFeatureBand sdkFeatureBand)
{
string[] coreComponents = SeparateCoreComponents(workloadSetVersion, out string[] sections);
string major = coreComponents[0];
string minor = coreComponents[1];
string patch = coreComponents[2];
string packageVersion = $"{major}.{patch}.";
if (coreComponents.Length == 3)
{
// No workload set patch version
packageVersion += "0";
// Use preview specifier (if any) from workload set version as part of SDK feature band
sdkFeatureBand = new SdkFeatureBand(workloadSetVersion);
}
else
{
// Workload set version has workload patch version (ie 4 components)
packageVersion += coreComponents[3];
// Don't include any preview specifiers in SDK feature band
sdkFeatureBand = new SdkFeatureBand($"{major}.{minor}.{patch}");
}
if (sections.Length > 1)
{
// Figure out if we split on a '-' or '+'
char separator = workloadSetVersion[sections[0].Length];
packageVersion += separator + sections[1];
}
return packageVersion;
} |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Combine nested boolean conditions