Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions QRCoder/QRCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
for (int i = 0; i < plainText.Length - 2; i += 3)
{
// Parse the next three characters as a decimal integer.
#if NET5_0_OR_GREATER
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
#if NETCOREAPP || NETSTANDARD2_1

I thinks this could be shortened for better legibility.
Older .NET Core targets than 2.1 aren't present. And .NET (5+) is covered by that compiler constant too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, as written:

  • it matches the rest of the codebase
  • it matches the conditions for which Span is supported

So I'd prefer to leave it as-is here for those reasons. Perhaps it would be better to have a compile time constant defined for span support - similar to SYSTEM_DRAWING we have SPAN - then in the csproj we define it for the applicable target frameworks. Then we change all uses to match.

var dec = int.Parse(plainText.AsSpan(i, 3), NumberStyles.None, CultureInfo.InvariantCulture);
#else
var dec = int.Parse(plainText.Substring(i, 3), NumberStyles.None, CultureInfo.InvariantCulture);
Expand All @@ -1021,7 +1021,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
// Handle any remaining digits if the total number is not a multiple of three.
if (plainText.Length % 3 == 2) // Two remaining digits are encoded in 7 bits.
{
#if NET5_0_OR_GREATER
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
var dec = int.Parse(plainText.AsSpan(plainText.Length / 3 * 3, 2), NumberStyles.None, CultureInfo.InvariantCulture);
#else
var dec = int.Parse(plainText.Substring(plainText.Length / 3 * 3, 2), NumberStyles.None, CultureInfo.InvariantCulture);
Expand All @@ -1030,7 +1030,7 @@ private static BitArray PlainTextToBinaryNumeric(string plainText)
}
else if (plainText.Length % 3 == 1) // One remaining digit is encoded in 4 bits.
{
#if NET5_0_OR_GREATER
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
var dec = int.Parse(plainText.AsSpan(plainText.Length / 3 * 3, 1), NumberStyles.None, CultureInfo.InvariantCulture);
#else
var dec = int.Parse(plainText.Substring(plainText.Length / 3 * 3, 1), NumberStyles.None, CultureInfo.InvariantCulture);
Expand Down