mapperly
mapperly copied to clipboard
Use UserMapping as global configuration
Hello every one
Is it possible to define a global configuration ?
I want to convert all Google.Protobuf.WellKnownTypes.Timestamp to DateTime as :
private DateTime? MapNullableDate(Google.Protobuf.WellKnownTypes.Timestamp date)
=> date?.ToDateTime();
Currently i should set my [UserMapping] in my partial class
[Mapper]
public partial class ProfileMapper
{
/// <summary> Profile to grpc </summary>
public partial ProfileBase GrpcProfileToProfile(GrpcProfile grpcProfile);
[UserMapping]
private DateTime MapDate(Google.Protobuf.WellKnownTypes.Timestamp date)
=> date?.ToDateTime() ?? new DateTime();
[UserMapping]
private DateTime? MapNullableDate(Google.Protobuf.WellKnownTypes.Timestamp date)
=> date?.ToDateTime();
}
But i want to set this config once, something like :
[Mapper]
public partial class ProfileMapper
{
/// <summary> Profile to grpc </summary>
public partial ProfileBase GrpcProfileToProfile(GrpcProfile grpcProfile);
}
public class GLOBALMapper
{
[UserMapping]
public DateTime MapDate(Google.Protobuf.WellKnownTypes.Timestamp date)
=> date?.ToDateTime() ?? new DateTime();
[UserMapping]
public DateTime? MapNullableDate(Google.Protobuf.WellKnownTypes.Timestamp date)
=> date?.ToDateTime();
}
Do you have some suggestion ?
Have nice day
Either extend your GlobalMapper or use it.