This project is read-only.

Problem flattering nullable DateTime

Jun 10, 2014 at 9:10 AM
The FlatteringConfig class contained in the assembly EMConfigurations cannot flatter objects containing nullable DateTimes.
To verify this, it is sufficient to define as DateTime? the properties BaseDate of the classes ModelObject and ModelDto of the class Flattering of the assembly SamplesTests: the test will give the exception "Property Date doesn't have set accessor".
This exception is due to the fact that the Nullable DateTime is considered as a complex type, so the FlatteringConfig tries to flatter also its properties, such as Date.

A possible solution is to define a converter function from DateTime? to DateTime? : even if it doesn't execute a real conversion, it permits to recognize the DateTime? as a simple type.
A way to do this, is to change the constructor of FlatteringConfig to this:

public FlatteringConfig()
nestedMembersMatcher = (m1, m2) => m1.StartsWith(m2);           

public class NullableDateTimeConverter
public static DateTime? ToDateTime(DateTime? from)
    return from;