-1

I would like to use FluentValidation to change the format of an input based on a second value

The example in the FluentValidation documentation I am following is: (although my values are all strings)

Transform(x => x.SomeStringProperty, StringToNullableInt)
    .GreaterThan(10);

int? StringToNullableInt(string value)
  => int.TryParse(value, out int val) ? (int?) val : null;

My method the Transform would call is:

public static string FormatPostCode(string postcode, string countryCode)

How do I pass the countryCode in the Transform statement?

1 Answers1

0

Assuming both PostCode and CountryCode are properties of your Class

The Transform statement would look like

Transform(x => x, x => FormatPostCode(x.PostCode, x.CountryCode));
Akshay G
  • 2,070
  • 1
  • 15
  • 33