public static void Initialize()
{
TypeAdapterConfig<string?, DateTime?>.NewConfig()
.MapWith(s => Convert(s));
}
private static DateTime? Convert(string? s) => DateTime.TryParseExact(
s, "dd/MM/yyyy", null, DateTimeStyles.None, out DateTime date) ? date : null;
Here's my workaround. If I didn't use the separate private method, the overloads of MapWith won't allow the ?
operator as the expression argument. Is there any other built-in way to achieve the same result?