You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I've seen some weird behavior when using the shouldMap option of the Map method. The wiki page regarding this feature explains that if the condition is not met, the destination property is set to null or default value. But the default value seems to be the one of the property's source type.
For instance, given the following classes:
public class Dest {
public DateTimeOffset? Start {get;set;}
}
public class Src {
public DateTimeOffset Start {get;set;}
public bool HasStart {get;set;}
}
Adapting Src to Dest with HasStart = false will give use the following result: Dest.Start = 0 (because 0 is the default value for a DateTimeOffset which is the type given in the mapping).
One of the solution I found to prevent this issue in my code is to cast the given type of the src to the destination type : NewConfig<Src, Dest>().Map(dest => dest.Start, src => src.Start as DateTimeOffset?, src => src.HasStart);
but this does not feel very natural.
To conclude, I am not sure if the issue comes from the code or the documentation. As explained, there is a easy fix for the time being, but maybe the wiki page could be updated accordingly or the code (depending of what feel more suitable)
The text was updated successfully, but these errors were encountered:
You can also use IgnoreIf to test condition and not map, Map setting will map to default value of source type if condition is not met. You can help update Wiki if it is confusing.
I will keep this issue open, and will try to fix if I have time. I agree that it is not natural.
Hello,
I've seen some weird behavior when using the
shouldMap
option of theMap
method. The wiki page regarding this feature explains that if the condition is not met, the destination property is set to null or default value. But the default value seems to be the one of the property's source type.For instance, given the following classes:
and the given configuration
Adapting Src to Dest with
HasStart = false
will give use the following result:Dest.Start = 0
(because 0 is the default value for a DateTimeOffset which is the type given in the mapping).One of the solution I found to prevent this issue in my code is to cast the given type of the src to the destination type :
NewConfig<Src, Dest>().Map(dest => dest.Start, src => src.Start as DateTimeOffset?, src => src.HasStart);
but this does not feel very natural.
To conclude, I am not sure if the issue comes from the code or the documentation. As explained, there is a easy fix for the time being, but maybe the wiki page could be updated accordingly or the code (depending of what feel more suitable)
The text was updated successfully, but these errors were encountered: