MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.38k stars 331 forks source link

Please add support to map into specific dictionary keys #445

Open cytoph opened 2 years ago

cytoph commented 2 years ago

It would be great if something like this would be possible:

config.NewConfig<DataRow, FormatDescriptor>()
    .Map(f => f.DateFormat, dr => dr.Field<string>("DateFormat"))
    // [...]
    .Map(f => f.DecimalDigits[DecimalType.None], dr => dr.Field<bool>("DigitsNone"))
    .Map(f => f.DecimalDigits[DecimalType.Rate], dr => dr.Field<bool>("DigitsRate"))
    .Map(f => f.DecimalDigits[DecimalType.Sum], dr => dr.Field<bool>("DigitsSum"))
    // [...]
    ;

Currently my only workaround for this is the following (which is kind of ugly):

config.NewConfig<DataRow, FormatDescriptor>()
    .Map(f => f.DateFormat, dr => dr.Field<string>("DateFormat"))
    // [...]
    .AfterMapping((dr, f) =>
    {
        f.DecimalDigits[DecimalType.None] = dr.Field<bool>("DigitsNone");
        f.DecimalDigits[DecimalType.Rate] = dr.Field<bool>("DigitsRate");
        f.DecimalDigits[DecimalType.Sum] = dr.Field<bool>("DigitsSum");
        // [...]
    };

Is something like this already possible in any way? If no, it would really be nice, to have that functionality.