Skip to content

Commit f3267f7

Browse files
committed
Add CopyTo extenion for old .NET
1 parent 103ffc7 commit f3267f7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

BinaryObjectScanner/OldDotNet.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if NET20 || NET35
2+
3+
using System;
4+
using System.IO;
5+
6+
namespace BinaryObjectScanner
7+
{
8+
/// <summary>
9+
/// Derived from the mscorlib code from .NET Framework 4.0
10+
/// </summary>
11+
internal static class OldDotNet
12+
{
13+
public static void CopyTo(this Stream source, Stream destination)
14+
{
15+
if (destination == null)
16+
{
17+
throw new ArgumentNullException("destination");
18+
}
19+
20+
if (!source.CanRead && !source.CanWrite)
21+
{
22+
throw new ObjectDisposedException(null);
23+
}
24+
25+
if (!destination.CanRead && !destination.CanWrite)
26+
{
27+
throw new ObjectDisposedException("destination");
28+
}
29+
30+
if (!source.CanRead)
31+
{
32+
throw new NotSupportedException();
33+
}
34+
35+
if (!destination.CanWrite)
36+
{
37+
throw new NotSupportedException();
38+
}
39+
40+
byte[] array = new byte[81920];
41+
int count;
42+
while ((count = source.Read(array, 0, array.Length)) != 0)
43+
{
44+
destination.Write(array, 0, count);
45+
}
46+
}
47+
}
48+
}
49+
50+
#endif

0 commit comments

Comments
 (0)