Skip to content

Commit f8ac1b2

Browse files
committed
Add <= and >= operator on GameVersion for .NET 10
Also reducing stackalloc size from 64 to 32 bytes in ToString() method
1 parent b634e8e commit f8ac1b2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Management/GameVersion.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@ public readonly GameVersion GetIncrementedVersion()
117117
/// <returns>A string representation of <see cref="GameVersion"/>.</returns>
118118
public readonly string ToString(string? format, IFormatProvider? formatProvider = null)
119119
{
120-
Span<char> writeStackalloc = stackalloc char[64];
121-
if (!TryFormat(writeStackalloc, out int written, format, formatProvider))
122-
{
123-
throw new InvalidOperationException("Cannot write string to stackalloc buffer!");
124-
}
125-
126-
return new string(writeStackalloc[..written]);
120+
scoped Span<char> writeStackalloc = stackalloc char[32];
121+
return !TryFormat(writeStackalloc, out int written, format, formatProvider)
122+
? throw new InvalidOperationException("Cannot write string to stackalloc buffer!")
123+
: new string(writeStackalloc[..written]);
127124
}
128125

129126
public static bool operator <(GameVersion? left, GameVersion? right) =>
@@ -136,6 +133,14 @@ public readonly string ToString(string? format, IFormatProvider? formatProvider
136133
public static bool operator >(GameVersion? left, GameVersion? right) =>
137134
right < left;
138135

136+
#if NET10_0_OR_GREATER
137+
public static bool operator <=(GameVersion? left, GameVersion? right) =>
138+
left < right || left == right;
139+
140+
public static bool operator >=(GameVersion? left, GameVersion? right) =>
141+
right < left || right == left;
142+
#endif
143+
139144
public static bool operator ==(GameVersion? left, GameVersion? right) =>
140145
left.HasValue && right.HasValue &&
141146
left.Value.Major == right.Value.Major &&

0 commit comments

Comments
 (0)