-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVersion.cs
More file actions
63 lines (57 loc) · 1.75 KB
/
Version.cs
File metadata and controls
63 lines (57 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
/// <summary>
/// Represents a version with major, minor, and subMinor components.
/// </summary>
struct Version
{
// Represents a zero-initialized Version.
internal static Version zero = new Version(0, 0, 0);
// Components of the version.
short major;
short minor;
short subMinor;
/// <summary>
/// Initializes a Version with specified components.
/// </summary>
internal Version(short _major, short _minor, short _subMinor)
{
major = _major;
minor = _minor;
subMinor = _subMinor;
}
/// <summary>
/// Parses a version string in the format "major.minor.subMinor". If the format is invalid, initializes the version to zero.
/// </summary>
internal Version(string _version)
{
string[] _versionStrings = _version.Split('.');
if (_versionStrings.Length != 3)
{
major = 0;
minor = 0;
subMinor = 0;
return;
}
major = short.Parse(_versionStrings[0]);
minor = short.Parse(_versionStrings[1]);
subMinor = short.Parse(_versionStrings[2]);
}
/// <summary>
/// Checks if the current version is different from another version.
/// </summary>
/// <returns> True if any component differs, otherwise returns false.</returns>
internal bool IsDifferentThan(Version _otherVersion)
{
if (major != _otherVersion.major || minor != _otherVersion.minor || subMinor != _otherVersion.subMinor)
{
return true;
}
return false;
}
/// <summary>
/// Overrides the ToString() method to represent the version as a string.
/// </summary>
public override string ToString()
{
return $"{major}.{minor}.{subMinor}";
}
}