Open Shane32 opened 5 months ago
The builder syntax could likely be added to v1.x as a new layer, as shown in this PR
QRCoder2.FluentExtensions
maybe? 😉
Hi Shane, thanks for the PR. That looks pretty interesting. However, I don't want to merge this into v1.x, but would like to include it in v2 first, as I don't want to make/document/communicate any more major API changes to v1. I hope that's okay with you.
Certainly. I wrote this more of a discussion/preview/review of a potential approach.
Summary
Experimentation with fluent API syntax
Samples
Intellisense samples
Preliminary Findings
new QRCodeBuilder.Email("test@microsoft.com")
rather thanQRCodeBuilder.CreateEmail("test@microsoft.com")
- which is pretty similar to the existingnew PayloadGenerator.Wifi()
syntax actually, with the difference being the fluent syntax for configuration. One benefit of usingnew
is that additional payloads can be added by simply adding a new class into the correct namespace. Whereas methods cannot be added toQRCodeBuilder
outside of QRCoder.RenderWith<T>
breaks the intellisense pattern because T does not give a list of the specific renderers available. Probably better to create an extension method for each renderer, likeRenderAsAscii()
andRenderAsPng(20)
insteadRenderWith<T>
does not allow for render-specific constructor parameters. I've compensated with support for only two patterns: (1) no arguments (2) pixels per module argument. HavingRenderAs...()
dedicated methods would allow each renderer to require specific arguments.RenderWith<T>
, as noted in item 2 above. Another reason to useRenderAsAscii()
or similar.ToArray
,ToStream
,ToFile
, etc) are really cool -- each renderer need only implementToStream
and all the other methods are available via extension methods. Similar functionality for text renderers; even with only implementingToString
they can also provideToFile
,ToStream
,ToBase64
, and so on via extension methods.