Closed MayurikaD closed 4 years ago
Hi @MayurikaD. What exception do you have?
I think the issue is because you use ? but not Value property for Nullable type. Try this:
DateTime? dt1 = new DateTime(2019, 1, 2);
DateTime? dt2 = new DateTime(2019, 1, 2);
var dateComparer = new DynamicValueComparer<DateTime?>
((date1, date2, settings) => date1 != null && date2 != null && date1.Value.Date == date2.Value.Date);
var comparer = new Comparer<DateTime?>();
comparer.AddComparerOverride<DateTime?>(dateComparer);
var result = comparer.Compare(dt1, dt2);
Hi thanks for your help. So this throws a System.ArgumentException when both (or any one) values are null.
@MayurikaD, can you provide the callstack? In what line do you have this exception? Otherwise I'll have a look next week.
@ValeraT1982 Hi here is the detail
@MayurikaD, try add date1.HasValue && date2.HasValue to the condition.
And condition should return true if both values are null.
If it doesn't work then I'll have a look next week.
Hi, tried with the HasValue check, but it still returns the same exception.
It looks like an issue with nulls in DynamicValueComparer. It will be fixed in the next version. As a workaround you can create class which implements AbstractValueComparer<DateTime?>and use it
Fixed in 1.4.0
I was trying to add a DynamicValueComparer to compare nullable dates, but I get an exception every time I try using this below:
var dateComparer = new DynamicValueComparer<DateTime?> ( (date1, date2, settings) => date1 != null && date2 != null && date1?.Date == date2?.Date);
Am I missing some implementation here?