16 public static Version
ChangeVersion(
this Version version,
string changeStr)
18 string[] subVersions = changeStr.Split(
'.');
19 int[] wrapValues = { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue };
20 int[] original = { version.Major, version.Minor, version.Build, version.Revision };
21 int[] versions = { version.Major, version.Minor, version.Build, version.Revision };
22 bool[] changeReset =
new bool[4];
24 for (
int i = 4 - 1; i >= 0; i--)
26 string current = subVersions[i];
28 if (current.StartsWith(
"("))
32 for (; j < current.Length; j++)
34 if (current[j] ==
')')
40 if (j == current.Length)
45 string max = current.Substring(1, j - 1);
49 changeReset[i] =
true;
51 else if (
int.TryParse(max, out
int newMax))
58 wrapValues[i] = newMax;
61 current = current.Remove(0, j + 1);
66 if (versions[i] >= wrapValues[i])
79 case "-" when versions[i] != 0:
85 if (current.ToLower(CultureInfo.InvariantCulture) ==
"x")
89 else if (current.StartsWith(
"{") && current.EndsWith(
"}"))
91 string format = current.Remove(current.Length - 1, 1)
94 string value = DateTime.Now.ToString(format);
96 if (
long.TryParse(value, out
long newValue))
98 versions[i] = (int)(newValue % ushort.MaxValue);
101 else if (
int.TryParse(current, out
int v))
113 return new Version(versions[0],
114 versions[1] < 0 ? 0 : versions[1],
115 versions[2] < 0 ? 0 : versions[2],
116 versions[3] < 0 ? 0 : versions[3]
128 IReadOnlyList<int> original,
131 for (
int j = 0; j < changeReset.Count; j++)
133 if (!changeReset[j] || versions[j] == original[j])
138 for (
int i = j + 1; i < versions.Count; i++)