Open
Conversation
|
A port to C# already exists. See https://www.nuget.org/packages/Net.Codecrete.QrCodeGenerator and https://github.com/manuelbl/QrCodeGenerator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(copied from ./csharp/PORTING.md)
Example demo run:

Porting Summary: Java → C# QR Code Generator
Scope
java/src/main/java/io/nayuki/qrcodegen/) to C#.QrCodeGenand a minimal console demoQrCodeGen.Demo.Goals
Note
Repository Layout (Relevant to this PR)
csharp/QR-Code-generator.sln— Solution file containing two projects.csharp/QrCodeGen/— Class library (C# port of the Java library):BitBuffer.csDataTooLongException.csQrSegment.csQrSegmentAdvanced.cs(simplified vs. Java; see Feature Parity section)QrCode.cscsharp/QrCodeGen.Demo/— Console demo app (depends onQrCodeGen).Class-by-Class Mapping
Java
BitBuffer→ C#BitBufferList<bool>and explicit bounds checks like Java’sBitSet/length pair.Java
DataTooLongException→ C#DataTooLongExceptionArgumentException(close analog to Java’sIllegalArgumentException).Java
QrSegment→ C#QrSegmentMakeBytes,MakeNumeric,MakeAlphanumeric,MakeEci.IsNumeric,IsAlphanumericvia regexes mirroring Java patterns.GetTotalBits()faithfully ported.Java
QrSegmentAdvanced→ C#QrSegmentAdvancedJava
QrCode→ C#QrCodeEncodeText,EncodeBinary.EncodeSegmentswithminVersion,maxVersion,mask, andboostEclparameters.ECC_CODEWORDS_PER_BLOCKandNUM_ERROR_CORRECTION_BLOCKSported exactly. Signedsbyteused to allow-1sentinels.Feature Parity
Achieved parity:
Intentional differences / limitations:
QrSegmentAdvanceddoes not implement:QrSegment.makeSegments()selection (numeric/alphanumeric/byte) and therefore preserves functional outputs for typical text.Behavioral equivalence expectations:
Notable C#-Specific Decisions
sbyte[][]tables for ECC metadata to accommodate-1sentinel (Java byte is signed; C# byte is unsigned).BitBuffercloning implemented to maintain immutability of exposed data as in Java.ArgumentException,ArgumentOutOfRangeException).Build and Run Instructions
net8.0(both projects). If your machine only has .NET 9, either install .NET 8 or retarget both projects tonet9.0.Commands from repo root:
dotnet restore csharp/QR-Code-generator.sln dotnet build csharp/QR-Code-generator.sln -c Debug # Run demo dotnet run --project csharp/QrCodeGen.DemoRider/VS:
csharp/QR-Code-generator.slnand build. Ensure your IDE uses the Microsoft .NET SDK (not Homebrew’s) and that the installed SDK matchesnet8.0or update TFM tonet9.0.Verification Performed
BitBufferlength; now we readnumDataBytes = bb.BitLength / 8and then apply 0xEC/0x11 padding.Reviewer Checklist
N1..N4and zigzag codeword placement logic mirror Java.BitBuffer.Known Gaps / Future Work
QrSegmentAdvanced:BitBufferto reduce allocations for very large payloads.Migration Risks and Mitigations
net9.0in both.csprojfiles./usr/local/share/dotnet; avoid Homebrew’s SDK confusion.QrSegmentAdvancedmay produce larger bitstreams for mixed-content strings vs. Java’s optimal splitter. This does not affect correctness, only compactness.File List (Added/Modified)
csharp/QR-Code-generator.slncsharp/QrCodeGen/QrCodeGen.csprojcsharp/QrCodeGen/BitBuffer.cscsharp/QrCodeGen/DataTooLongException.cscsharp/QrCodeGen/QrSegment.cscsharp/QrCodeGen/QrSegmentAdvanced.cscsharp/QrCodeGen/QrCode.cscsharp/QrCodeGen.Demo/QrCodeGen.Demo.csprojcsharp/QrCodeGen.Demo/Program.csHow Reviewers Can Reproduce
maskinEncodeSegments) over several sample strings.License Alignment
Appendix: Usage Example