Skip to content

Commit 48ae1ce

Browse files
committed
Use throw helpers
1 parent 6ffdcad commit 48ae1ce

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

QRCoder/QRCodeGenerator.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ private static bool IsInRange(char c, char min, char max)
970970

971971
private static Polynom CalculateMessagePolynom(BitArray bitArray, int offset, int count)
972972
{
973-
var messagePol = new Polynom(count / 8);
974-
for (var i = count / 8 - 1; i >= 0; i--)
973+
var messagePol = new Polynom(count /= 8);
974+
for (var i = count - 1; i >= 0; i--)
975975
{
976976
messagePol.PolyItems.Add(new PolynomItem(BinToDec(bitArray, offset, 8), i));
977977
offset += 8;
@@ -1003,7 +1003,7 @@ private static byte[] BinaryStringToBitBlockByteList(BitArray bitString, int off
10031003
{
10041004
const int blockSize = 8;
10051005
if (count % blockSize != 0)
1006-
throw new ArgumentException("Count must be a multiple of 8.", nameof(count));
1006+
ThrowArgumentException(nameof(count));
10071007
var numberOfBlocks = (int)((uint)count / blockSize);
10081008
var blocklist = new byte[numberOfBlocks];
10091009

@@ -1023,6 +1023,8 @@ private static byte[] BinaryStringToBitBlockByteList(BitArray bitString, int off
10231023
}
10241024

10251025
return blocklist;
1026+
1027+
void ThrowArgumentException(string paramName) => throw new ArgumentOutOfRangeException(paramName, "Count must be a multiple of 8.");
10261028
}
10271029

10281030
private static int BinToDec(BitArray bitArray, int offset, int count)
@@ -1350,8 +1352,10 @@ private static int GetIntValFromAlphaExp(int exp)
13501352
private static int GetAlphaExpFromIntVal(int intVal)
13511353
{
13521354
if (intVal == 0)
1353-
throw new ArgumentOutOfRangeException(nameof(intVal));
1355+
ThrowArgumentOutOfRangeException(nameof(intVal));
13541356
return galoisFieldByIntegerValue[intVal];
1357+
1358+
void ThrowArgumentOutOfRangeException(string paramName) => throw new ArgumentOutOfRangeException(paramName);
13551359
}
13561360

13571361
private static int ShrinkAlphaExp(int alphaExp)

0 commit comments

Comments
 (0)