forked from microsoft/azure-pipelines-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersionParser.cs
40 lines (34 loc) · 1.02 KB
/
VersionParser.cs
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
internal static class VersionParser
{
public static void ParseVersion(
String version,
out Int32 major,
out Int32 minor,
out Int32 patch,
out String? semanticVersion)
{
ArgumentUtility.CheckStringForNullOrEmpty(version, "version");
String[] segments = version.Split(new char[] { '.', '-' }, StringSplitOptions.None);
if (segments.Length < 3 || segments.Length > 4)
{
throw new ArgumentException("wrong number of segments");
}
if (!Int32.TryParse(segments[0], out major))
{
throw new ArgumentException("major");
}
if (!Int32.TryParse(segments[1], out minor))
{
throw new ArgumentException("minor");
}
if (!Int32.TryParse(segments[2], out patch))
{
throw new ArgumentException("patch");
}
semanticVersion = null;
if (segments.Length == 4)
{
semanticVersion = segments[3];
}
}
}