c# Fluent Validation RuleFor

1k Views Asked by At

I am trying to find, if possible, to step into the validator class (MediatR) where Fluent Validation is being used. Something like this:

When(x=> x.Count != Null && x.Count >= 0 , () => 
{
    RuleFor(x=> x.Offset).Matches(isNumber errCode.somethingwrong);    
    RuleFor(x=> x.Offset).NotNull())); 
}

When setting watch on Count or Offset (even though I know what it is the Handler) can not see it. Any clues how to see the value? Reason I ask is that seems the When condition, and program falls into the When block. Either way would like to know if these variables are accessible to view when on break point. .Net core 3.1 vs2019

1

There are 1 best solutions below

0
On

Not entirely sure what you need, but how about a little trick to just log to the console if you can't catch it from the debugger.

You can maybe just make a function which always returns true and is called from the WHEN.

private bool logData(object x)
{
    Console.WriteLine(x.y);
    return true;
}

Change object into the variable type you require and log data to the console or just pause the debugger on that line to view the object on runtime.

And just add the function as a requirement to your When predicate:

When( x=> x.Count != Null && x.Count >= 0
      && logData(x), () => { ... }