Skip to content

Commit 5f70ec2

Browse files
committed
Use Stream.ReadExactly on .NET 7
1 parent 4600382 commit 5f70ec2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/CommunityToolkit.HighPerformance/Extensions/StreamExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ public static void Write(this Stream stream, ReadOnlySpan<byte> buffer)
205205
public static unsafe T Read<T>(this Stream stream)
206206
where T : unmanaged
207207
{
208-
#if NETSTANDARD2_1_OR_GREATER
209-
T result = default;
208+
#if NET7_0_OR_GREATER
209+
T result;
210+
211+
stream.ReadExactly(new Span<byte>(&result, sizeof(T)));
212+
213+
return result;
214+
#elif NETSTANDARD2_1_OR_GREATER
215+
T result;
210216
int bytesOffset = 0;
211217

212218
// As per Stream.Read's documentation:

0 commit comments

Comments
 (0)