Skip to content

Commit e7c8df7

Browse files
committed
Refactor compatibility extension methods
1 parent e3664d1 commit e7c8df7

File tree

3 files changed

+19
-41
lines changed

3 files changed

+19
-41
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
6-
namespace QRCoder.Framework4._0Methods
1+
#if NET35
2+
namespace QRCoder
73
{
8-
class Stream4Methods
4+
internal static class StreamExtensions
95
{
10-
public static void CopyTo(System.IO.Stream input, System.IO.Stream output)
6+
/// <summary>
7+
/// Copies a stream to another stream.
8+
/// </summary>
9+
public static void CopyTo(this System.IO.Stream input, System.IO.Stream output)
1110
{
1211
byte[] buffer = new byte[16 * 1024];
1312
int bytesRead;
@@ -18,3 +17,4 @@ public static void CopyTo(System.IO.Stream input, System.IO.Stream output)
1817
}
1918
}
2019
}
20+
#endif

QRCoder/Framework4.0Methods/String4Methods.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ namespace QRCoder
55
internal static class String40Methods
66
{
77
/// <summary>
8-
/// The IsNullOrWhiteSpace method from Framework4.0
8+
/// Indicates whether the specified string is null, empty, or consists only of white-space characters.
99
/// </summary>
1010
/// <returns>
11-
/// <c>true</c> if the <paramref name="value"/> is null or white space; otherwise, <c>false</c>.
11+
/// <see langword="true"/> if the <paramref name="value"/> is null, empty, or white space; otherwise, <see langword="false"/>.
1212
/// </returns>
1313
public static bool IsNullOrWhiteSpace(String value)
1414
{
15+
#if NET35
1516
if (value == null) return true;
1617

1718
for (int i = 0; i < value.Length; i++)
@@ -20,29 +21,9 @@ public static bool IsNullOrWhiteSpace(String value)
2021
}
2122

2223
return true;
23-
}
24-
25-
public static string ReverseString(string str)
26-
{
27-
char[] chars = str.ToCharArray();
28-
char[] result = new char[chars.Length];
29-
for (int i = 0, j = str.Length - 1; i < str.Length; i++, j--)
30-
{
31-
result[i] = chars[j];
32-
}
33-
return new string(result);
34-
}
35-
36-
public static bool IsAllDigit(string str)
37-
{
38-
foreach (var c in str)
39-
{
40-
if (!char.IsDigit(c))
41-
{
42-
return false;
43-
}
44-
}
45-
return true;
24+
#else
25+
return string.IsNullOrWhiteSpace(value);
26+
#endif
4627
}
4728
}
4829
}

QRCoder/QRCodeData.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
3-
using System.Linq;
4+
using System.IO;
5+
using System.IO.Compression;
46

57
namespace QRCoder
68
{
7-
using QRCoder.Framework4._0Methods;
8-
using System;
9-
using System.IO;
10-
using System.IO.Compression;
11-
129
public class QRCodeData : IDisposable
1310
{
1411
public List<BitArray> ModuleMatrix { get; set; }
@@ -48,7 +45,7 @@ public QRCodeData(byte[] rawData, Compression compressMode)
4845
{
4946
using (var dstream = new DeflateStream(input, CompressionMode.Decompress))
5047
{
51-
Stream4Methods.CopyTo(dstream, output);
48+
dstream.CopyTo(output);
5249
}
5350
bytes = new List<byte>(output.ToArray());
5451
}
@@ -62,7 +59,7 @@ public QRCodeData(byte[] rawData, Compression compressMode)
6259
{
6360
using (var dstream = new GZipStream(input, CompressionMode.Decompress))
6461
{
65-
Stream4Methods.CopyTo(dstream, output);
62+
dstream.CopyTo(output);
6663
}
6764
bytes = new List<byte>(output.ToArray());
6865
}

0 commit comments

Comments
 (0)