codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.59k stars 1.09k forks source link

Make QRCoder trimmable and add trimming tests #539

Closed Shane32 closed 4 months ago

Shane32 commented 4 months ago

Summary

This marks the QRCoder project as trimmable and fixes existing trim warnings within the project.

Changes / notes

  1. The RussianPaymentOrder payload generator uses reflection to add all properties to a list. Users cannot provide their own derived class, so the property list is known. As such, reflection is not even necessary. However, by simply referencing the exact type in the code, trimming analysis will know to preserve all the relevant fields.
  2. The SVG generator uses reflection to pull an associated string value (mime type) from an enum. Similar to above, the type of the enum examined is always known and cannot change, so reflection is unnecessary. In this instance I changed the code to use a switch case to return the proper mime type, eliminating the use of reflection. The code that used reflection was publicly accessible and remains (marked as obsolete) to maintain binary backwards compatibility. It is quite unlikely any users ever referenced these members, of course.

Test plan

Pursuant to MS docs, a new project has been added, that when published, performs trim analysis on QRCoder. Trim analysis has been configured to fail the publish. CI has been configured to 'publish' this upon running the tests.

Closing issues

Closes #537

Shane32 commented 4 months ago

@csturm83 Didn't realize you were going to work on this! Apparently you pushed a PR just around the same time I did!

Shane32 commented 4 months ago

To see how the trimmable tests work, look at the first CI run in this PR. You'll see something like this:

image

codebude commented 4 months ago

Well done! Had to find a minute to learn about trimming and its use cases, to then review your PR. Looks good to me. Thanks!

codebude commented 4 months ago

Updated the release notes: https://github.com/codebude/QRCoder/wiki/Release-Notes/_compare/f245943d08e6efb9810f10313a80150b168b506f...ed3367a8fdde6c8ebbfa2d07b38fd2033b001d72

Let me know if I missed anything (or if you see room for improvements).