MapsterMapper / MapsterMapper/Mapster
How migrate AutoMapper to Mapster - ConvertUsing
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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