Skip to content

Commit 8ff3639

Browse files
committed
Add extension method for Framework build
1 parent 44fa49f commit 8ff3639

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.NET.TestFramework.Utilities
5+
{
6+
internal static class BitConverterExtensions
7+
{
8+
extension(BitConverter)
9+
{
10+
public static uint ToUInt32(ReadOnlySpan<byte> value)
11+
{
12+
var buffer = new byte[4];
13+
value.CopyTo(buffer);
14+
return BitConverter.ToUInt32(buffer, 0);
15+
}
16+
}
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.NET.TestFramework.Utilities
5+
{
6+
internal static class StreamExtensions
7+
{
8+
extension(Stream stream)
9+
{
10+
public void ReadExactly(Span<byte> buffer)
11+
{
12+
int bytesRead = 0;
13+
byte[] arrayBuffer = new byte[buffer.Length];
14+
while (bytesRead < buffer.Length)
15+
{
16+
int read = stream.Read(arrayBuffer, bytesRead, buffer.Length - bytesRead);
17+
if (read == 0)
18+
{
19+
throw new EndOfStreamException("Unexpected end of stream while reading Mach-O file.");
20+
}
21+
bytesRead += read;
22+
}
23+
arrayBuffer.CopyTo(buffer);
24+
}
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)