Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UserMapping as global configuration #1279

Closed
btbenjamin opened this issue May 7, 2024 · 1 comment
Closed

Use UserMapping as global configuration #1279

btbenjamin opened this issue May 7, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@btbenjamin
Copy link

btbenjamin commented May 7, 2024

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

@btbenjamin btbenjamin added the enhancement New feature or request label May 7, 2024
@latonz
Copy link
Contributor

latonz commented May 7, 2024

Either extend your GlobalMapper or use it.

@latonz latonz closed this as completed May 28, 2024
@latonz latonz closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants