I'm working with FluentValidator in .NET Core. Everything is working beautifully for the most part, but I notice that when working with complex types, FluentValidator shows the full property name. For example, let's say I have a class named Address with Street, City, State, and Zip properties. Now let's say I have a form backed by a model property named Physical Address. If I make the street required, Fluent shows the following validation error:
'Physical Address. Street' must not be empty.
I prefer this to it just saying "Street" must not be empty because I might have multiple address fields on the page, so just displaying "Street" isn't specific enough. But I'd rather have it say:
'Physical Address Street' must not be empty.
(with no period after the word address)
The example given by FluentValidation to globally override the display name is adding this in Startup.cs:
ValidatorOptions.DisplayNameResolver = (type, member, expression) => {
if(member != null) {
return member.Name + "Foo";
}
return null;
};
The override example works, but using this (minus the foo part) displays this validation error:
'Street' must not be empty.
(the very thing I don't want because it's too generic)
What I need to know is what logic inside the lambda would produce the exact same result as the default behavior (i.e. Physical Address. Street, not just Street). Once I know that, I can fix removing the period with a simple defaultValue.Replace(".","")
. Thanks!