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.

nullable reference types support

See original GitHub issue

Some thoughts:

  • C# 8 introduces nullable reference types, and therefore non-nullable reference types
  • FluentValidation API could then be enhanced and DRY’d up a bit to support even more fluent syntax
    • When builder syntax today is reflexive to the parent, not the property.
RuleFor(s => s.NullableReferenceProperty)
    .NotEmpty()
    // WhenNotNull wouldnt be possible if NON-NullableReferenceProperty
    .WhenNotNull(); // more succinct than: .When(s => s.NullableReferenceProperty.HasValue);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
JeremySkinnercommented, May 15, 2019

It’s trivial to implement a WhenNotNull method today which works against both reference types and nullable value types:

public static IRuleBuilderOptions<T,TProperty> WhenNotNull<T,TProperty>(this IRuleBuilderOptions<T,TProperty> rule) {
	return rule.Configure(cfg => {
		cfg.ApplyCondition(ctx => ctx.PropertyValue != null);
	});
}

I’m not following how c# 8’s nullable reference types would make any difference to this?

0reactions
JeremySkinnercommented, May 16, 2019

Yes I’ve read that before, I do understand nullable reference types and their impact. What I’m not understanding is what you expect FluentValidation to be doing differently. Do you have a specific example of how you’d expect the behaviour to change?

I did not make the mental connection that .When is a syntax for Configure.

Yes most methods in the public API are just wrappers around Configure, which provides access to the underlying model.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullable reference types
Nullable reference types refers to a group of features enabled in a nullable aware context that minimize the likelihood that your code causes ......
Read more >
Nullable reference types - C# reference
Nullable reference types aren't new class types, but rather annotations on existing reference types. The compiler uses those annotations to help ...
Read more >
Digging Into Nullable Reference Types in C#
Enabling Nullable Reference Types · PropertyGroup · OutputType · OutputType · TargetFramework · TargetFramework · ImplicitUsings · ImplicitUsings ...
Read more >
Nullable Reference types in C# – Best practices
In this tutorial, I look at the state of the Nullable Reference Types feature in C#, one year after its initial release.
Read more >
What are nullable reference types in C# 8.0?
As the name suggests, nullable reference types may be null . When variables may be null , the compiler enforces specific rules to...
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