This code will pass, and shouldn't.
public record EmptyString([Required]string Name);
var context = new ValidationContext(src, null, null);
var es = new EmptyString("");
bool valid = Validator.TryValidateObject(src, context, results, true);
Assert.IsTrue(valid);
// ???? this shows up as valid! When it's clearly NOT!
Add property:
in front of Required, and suddenly it works. But first code (above) does not give a compile error!
// add property to line below see
public record EmptyString([property:Required]string Name);
var context = new ValidationContext(src, null, null);
var es = new EmptyString("");
bool valid = Validator.TryValidateObject(src, context, results, true);
// suddenly we get correct behaviour.
Assert.IsFalse(valid);
is this a C# 9 bug, or am I missing something? Txs
Alan