private UnityVersion From(int major, int minor, int build, UnityVersionType type, int typeNumber) { ulong data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32) | ((ulong)((int)type & 0xFF) << 24) | ((ulong)(typeNumber & 0xFF) << 16) | (0x000000000000FFFFUL & m_data); return(new UnityVersion(data)); }
public static string ToLiteral(this UnityVersionType _this) { switch (_this) { case UnityVersionType.Alpha: return("a"); case UnityVersionType.Beta: return("b"); case UnityVersionType.Final: return("f"); case UnityVersionType.Patch: return("p"); default: throw new Exception($"Unsupported vertion type {_this}"); } }
public static UnityVersion Parse(string version) { if (string.IsNullOrEmpty(version)) { throw new Exception($"Invalid version number {version}"); } int major = 0; int minor = 0; int build = 0; UnityVersionType versionType = UnityVersionType.Final; int typeNumber = 0; using (StringReader reader = new StringReader(version)) { while (true) { int symb = reader.Read(); if (symb == -1) { throw new Exception($"Invalid version format"); } char c = (char)symb; if (c == '.') { break; } major = major * 10 + c.ParseDigit(); } while (true) { int symb = reader.Read(); if (symb == -1) { break; } char c = (char)symb; if (c == '.') { break; } minor = minor * 10 + c.ParseDigit(); } while (true) { int symb = reader.Read(); if (symb == -1) { break; } char c = (char)symb; if (char.IsDigit(c)) { build = build * 10 + c.ParseDigit(); } else { switch (c) { case 'a': versionType = UnityVersionType.Alpha; break; case 'b': versionType = UnityVersionType.Beta; break; case 'p': versionType = UnityVersionType.Patch; break; case 'f': versionType = UnityVersionType.Final; break; default: throw new Exception($"Unsupported version type {c} for version '{version}'"); } break; } } while (true) { int symb = reader.Read(); if (symb == -1) { break; } char c = (char)symb; typeNumber = typeNumber * 10 + c.ParseDigit(); } } return(new UnityVersion(major, minor, build, versionType, typeNumber)); }
public bool IsGreaterEqual(int major, int minor, int build, UnityVersionType type, int typeNumber) => this >= new UnityVersion(major, minor, build, type, typeNumber);
public bool IsGreaterEqual(int major, int minor, int build, UnityVersionType type) => this >= From(major, minor, build, type);
public UnityVersion(int major, int minor, int build, UnityVersionType type, int typeNumber) { m_data = ((ulong)(major & 0xFFFF) << 48) | ((ulong)(minor & 0xFF) << 40) | ((ulong)(build & 0xFF) << 32) | ((ulong)((int)type & 0xFF) << 24) | ((ulong)(typeNumber & 0xFF) << 16); }
public bool IsLessEqual(int major, int minor, int build, UnityVersionType type) => this <= From(major, minor, build, type);
public bool IsLess(int major, int minor, int build, UnityVersionType type, int typeNumber) => this < new UnityVersion(major, minor, build, type, typeNumber);