Closed pleonex closed 9 months ago
Good feedback from trying in some projects (PokΓ©mon Conquest and Ekona):
TransformTo
, ConvertFormat.To
because some converters have now constructors with parameters (not very often).IConverter<,>
per class.TransformTo
and ConvertFormat.To
APIs to the new API.IInitializer<T>
with a constructor: move same code and allow to use readonly
, reference null checks and remove initialization checks in Convert()
Description
This PR proposes a new API to use converters on
IFormat
variables and via theNode
class. It tries to address the issues collected from users where the current API can be very verbose or confusing.The new API is:
Examples at the bottom
Main changes:
IFormat
allowing fluent-like chain conversions:myFormat.ConvertWith(new Converter1()).ConvertWith(new Converter2())
po.ConvertWith(new Po2Binary(args))
IInitializer<T>
. Use instead the constructor to pass parameters or initialize the converter.ConvertFormat.To()
andNode.TransformTo()
are removed.This new design does not require having dependencies in the core library (Yarhl) with an assembly scanning tech or DI (like MEF)
Cons
IDisposable
saying we didn't dispose the object. I added the argument in the extension method but the analyzer won't detect it.using var
and pass the objectsConvertWith(new Po2Binary(arg1))
vsConvertWith<Po2Binary>(arg1)
which is cooler) but we couldn't find a way to make it work and being type-safe.IConverter<,>
, then the generics in the extension methodConvertWith
cannot be omitted.Options considered
po.ConvertWith<Po2Binary, Args>(args).To<BinaryFormat>()
vspo.ConvertWith(new Po2Binary(args))
Requirements analyzed
ConvertTo
)IFormat
can be chained for multiple conversionsNode
can be converted without affecting the node easilyIConverter<,>
)TODO
ConsiderNode.TransformWith<TConv>(args)
Fix / Replace MEF (plugin discovery)Future PR. PoC in SceneGateExample
Performance results
TransformWith<TSrc, TDst>(IConverter<TSrc, TDst> converter)
vsTransformWith(IConverter converter)
(usesdynamic
):For now most of the old API is not removed but marked them as obsolete. It allows to do a smooth migration part by part.
Please feel free to provide feedback and try in your projects.
I have temporary modify the build pipeline so there is a NuGet version for this branch available in the preview feed. Version:
4.0.0-PullRequest0191.191
(the last digit may increase)I'll leave this PR open some time while we test it in our projects, so we can validate it.
Internal validation:
This closes #124