For example I have ObjectA:
public class ObjectA {
public int ID { get; set; }
public UserInfo UserInfo { get; set; }
}
and ObjectB:
public class ObjectB {
public int ID { get; set; }
public IDataUserInfo UserInfo { get; set; }
}
I want to map ObjectA to ObjectB. IDataUserInfo
is an interface and there is an implementation for this interface called DataUserInfo
. Both UserInfo
from ObjectA and ObjectB have absolutely the same structure.
But after I call:
instanceOfObjectA.Adapt<ObjectB>();
I see that the actual type of the UserInfo
field is GeneratedType_1
. This is expected because our mapster doesn't know anything about our implementation of the IDataUserInfo
interface.
How can I tell Mapster to use a specific implementation when materializing IDataUserInfo
interface? I tried the following config but it still shows GeneratedType_1
instead of DataUserInfo
:
public class MappingConfig : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<ObjectA, ObjectB>()
.Map(dest => dest.UserInfo, src => new DataUserInfo { Field1 = src.UserInfo.Field1, ... });
}
}