Open
Description
When converting between two class, both of which have a property named MyProperty
with different types (one is string and the other is int),
I have configured RequireExplicitMapping = true
.
I expected an exception to occur during the Compile
phase, indicating that I should explicitly configure the conversion between these two properties. However, that did not happen. The error only occurs at runtime if the conversion fails.
Is there any way to avoid this situation?
Mapster version: 7.4.0
// PatientInformation
public string MyProperty { get; set; } = "";
// PatientInfoViewObject
public int MyProperty { get; set; }
public static void ConfigureMappings()
{
TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;
ConfigurePatientInfoMappings();
// expect an exception here
TypeAdapterConfig.GlobalSettings.Compile();
// test code
var info = new PatientInformation();
info.MyProperty = "test";
var viewObject = info.Adapt<PatientInfoViewObject>();
}
private static void ConfigurePatientInfoMappings()
{
TypeAdapterConfig<PatientInformation, PatientInfoViewObject>.NewConfig();
TypeAdapterConfig<PatientInfoViewObject, PatientInformation>.NewConfig();
}