WKLib 0.2.3
A modding library for White Knuckle
Loading...
Searching...
No Matches
WKVersion.cs
Go to the documentation of this file.
1using System;
2using System.Text.RegularExpressions;
3
5
6public struct WKVersion : IComparable<WKVersion>
7{
8 public int Major;
9 public int Minor;
10 public string Suffix;
11
12 public WKVersion(string version)
13 {
14 // Regex match version, eg. "0.55m"
15 var match = Regex.Match(version, @"(\d+)\.(\d+)([a-z]?)");
16 if (match.Success)
17 {
18 Major = int.Parse(match.Groups[1].Value);
19 Minor = int.Parse(match.Groups[2].Value);
20 // Default to "a" if not version "0.55" is the same as "0.55a"
21 Suffix = string.IsNullOrWhiteSpace(match.Groups[3].Value) ? "a" : match.Groups[3].Value;
22 }
23 else
24 {
25 Major = Minor = 0;
26 Suffix = "a";
27 }
28 }
29
30 public int CompareTo(WKVersion other)
31 {
32 if (Major != other.Major) return Major.CompareTo(other.Major);
33 if (Minor != other.Minor) return Minor.CompareTo(other.Minor);
34 return String.Compare(Suffix, other.Suffix, StringComparison.Ordinal);
35 }
36
37 public static bool operator >=(WKVersion a, WKVersion b) => a.CompareTo(b) >= 0;
38 public static bool operator <=(WKVersion a, WKVersion b) => a.CompareTo(b) <= 0;
39 public static bool operator >(WKVersion a, WKVersion b) => a.CompareTo(b) > 0;
40 public static bool operator <(WKVersion a, WKVersion b) => a.CompareTo(b) < 0;
41}
static bool operator<=(WKVersion a, WKVersion b)
static bool operator>(WKVersion a, WKVersion b)
static bool operator>=(WKVersion a, WKVersion b)
static bool operator<(WKVersion a, WKVersion b)
WKVersion(string version)
Definition WKVersion.cs:12
int CompareTo(WKVersion other)
Definition WKVersion.cs:30