forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemVer.cs
More file actions
51 lines (44 loc) · 1.44 KB
/
SemVer.cs
File metadata and controls
51 lines (44 loc) · 1.44 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
namespace PluginCore.Utilities
{
/// <summary>
/// Represents a semantic version, see http://semver.org/
/// </summary>
public class SemVer
{
public static readonly SemVer Zero = new SemVer();
public readonly int Major;
public readonly int Minor;
public readonly int Patch;
private SemVer()
{
}
public SemVer(string version)
{
// ignore the pre-release denotation if present
int hyphenIndex = version.IndexOf('-');
if (hyphenIndex >= 0)
version = version.Substring(0, hyphenIndex);
string[] numbers = version.Split('.');
if (numbers.Length >= 1)
int.TryParse(numbers[0], out Major);
if (numbers.Length >= 2)
int.TryParse(numbers[1], out Minor);
if (numbers.Length >= 3)
int.TryParse(numbers[2], out Patch);
}
public override string ToString()
{
return string.Format("{0}.{1}.{2}", Major, Minor, Patch);
}
public bool IsOlderThan(SemVer semVer)
{
if (semVer.Major > Major)
return true;
if (semVer.Major == Major && semVer.Minor > Minor)
return true;
if (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch > Patch)
return true;
return false;
}
}
}