MapsterMapper / MapsterMapper/Mapster

How migrate AutoMapper to Mapster - ConvertUsing

Open
#910 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

configuration problem
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Please help me migrate from AutoMapper to Mapster

using Mapster;

namespace Mappers
{
public class SampleRegister : IRegister
{
public void Register(TypeAdapterConfig config)
{
// Map ICollection to string
config.NewConfig<ICollection, string>()
.ConvertUsing(src =>
{
if (src == null || !src.Any())
{
return null;
}

                // Note: You could also replace this with string.Join(",", src)
                return src.Aggregate((x, y) => $"{x},{y}");
            });

        // Map string to ICollection<string> (Specifically HashSet<string>)
        config.NewConfig<string, HashSet<string>>()
            .ConvertUsing(src =>
            {
                var list = new HashSet<string>();
                if (!string.IsNullOrWhiteSpace(src))
                {
                    src = src.Trim();
                    foreach (var item in src.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct())
                    {
                        list.Add(item);
                    }
                }
                return list;
            });
    }
}

}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the provided SampleRegister code and Mapster's ConvertUsing API to determine how the AutoMapper conversion is expected to translate. The issue names no repository file, test, failure, or concrete change; it is complete only when the required ICollection and string conversion behavior is clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.