Closed bartoszlenar closed 2 years ago
Hello @bartoszlenar, I'd like to know if there's any pans of adding this feature? Thank you a lot for your work on this library!
Hi @tim-fay. Sorry for the late reply, I'm on my holidays until the end of month.
I haven't abandoned the project, but the pace slowed down significantly lately. Partially because I don't know what other developers really want from this lib. And now I do, thanks to you.
Thank you for adding your comment and please expect this feature... well... this year for sure. Alongside other features I'm slowly (but consistently!) adding to the codebase.
@tim-fay I'm on the task and so far, this is the progress with the planning:
.AsType(tryConvertFunction, specification)
, so everything in a single one, without a separate command for the error message. Why? AsType<TargetType>
doesn't work in the fluent API unfortunately, because all commands already have the first generic parameter. So it's either taken from the arguments, or you need to deliver both generic parameter (like AsType<TSource, TTarget>
). Same reason for specification as the second parameter - it's just convenient to deliver the conversion method first so then compiler knows what is the TTarget
in the Specification<TTarget>
..AsType(convertFunction, specification)
will be delivered which works exactly the same, but it doesn't assume the conversion could fail.Please expect the feature sooner rather than later 😄
The final version for this api is:
.AsConverted(converted, specification)
.
converter
is the standard dotnet's Converter<TInput, TOutput>
Specifiction<TOutput>
, where TOutput
is determined by the given converted
declarationAsType
becomes AsConverted
, because technically nothing stops you from using it as a method to pre-process the value before the further validation (so no change of type, just a little bit of work over the scope value)AsConverted
doesn't assume the conversion could fail. You can always add WithCondition
to make it conditional. If a try-DoSomething
mechanism is required, it will be added in the subsequent versions.Merged to the main branch with this commit: https://github.com/bartoszlenar/Validot/commit/d379a9912e8df5b02217e51410634a2140afbc09
Feature description
Feature in action
Full custom option:
Predefined options:
Feature details
AsType<T>
.WithConversion
parameter command that would set the conversion logicWithConversion
in fluent api? It is possible ifAsType
would allow only one following command and NOTISpecificationOut
.WithConversionErrorMessage
- optional, setting error message.AsInt
,AsString
, etc.