question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional transforms

See original GitHub issue

Is your feature request related to a problem? Please describe. The upcoming changes to Transform in v10 poses some problems for us. In particular that it’s no longer possible to easily combine a condition with a transform. We currently have these extension methods to easily work with nullable values. Basically, if the value is null, don’t validate the property:

public static IRuleBuilderInitial<T, TValue> WithNonNullCondition<T, TValue>(this IRuleBuilderInitial<T, TValue> rule)
    => rule.Configure(r => r.ApplySharedCondition(c => r.PropertyFunc(c.InstanceToValidate) is not null));

public static IRuleBuilder<T, TValue> WhenNotNull<T, TValue>(this IRuleBuilderInitial<T, TValue?> rule)
    where TValue : class
    => rule.WithNonNullCondition().Transform(value => value!);

public static IRuleBuilder<T, TValue> WhenNotNull<T, TValue>(this IRuleBuilderInitial<T, TValue?> rule)
    where TValue : struct
    => rule.WithNonNullCondition().Transform(value => value!.Value);

That’s no longer doable with the new approach.

The other aspect of this problem is that it’s no longer possible to do this type of stuff as an extension method, because they are now protected methods on AbstractValidator. This makes it a bit hard to make custom extensions that don’t require usage of a different base class (which is doable, but requires some education of developers)

Describe the solution you’d like Some way to only apply the rule if some condition is met.

Describe alternatives you’ve considered Tried implementing as extension method on new API, but does not seem possible.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mvestergaardcommented, Mar 22, 2021

Got everything up and running, and tests are now passing with FV 10.0.0-preview3. Closing this one 😃

0reactions
mvestergaardcommented, Mar 22, 2021

Awesome, thanks Jeremy, will check it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional transformations
Conditional transformations are used to either add new columns or to remove rows from a dataframe based on one or more conditions.
Read more >
Conditional Image Transformation Expressions
Cloudinary supports conditional transformations for images, where a transformation is only applied if a specified condition is met, for example, ...
Read more >
Conditional
Use the conditional transform to output different values depending on simple conditional logic. This is a convenient transform - the same ...
Read more >
Conditional Transformation | Superpower Wiki - Fandom
The power to transform under certain conditions. Variation of Transformation. Conditional Transforming Limited Transforming Situational Transformation The ...
Read more >
Conditional Transformations
Conditional transformations are parts of ST programs that are considered during program execution only if certain prerequisites are met.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found