Skip to content

jangocheng/Mapper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Features

MapperFramework is a NuGet library that you can add in to your project.

How do I get started?

First, configure MapperFramework to know what types you want to map, in the startup of your application:

Mapper.MapConfiguration(cfg =>
            {
                cfg.CreateMap<StudentModel, Dto.StudentModel()
                    .Property(wm => wm.CityName, m => m.CityModel == null ? null : m.CityModel.Name)
                    // You can use "IfNotNull" extensions.
                    //.Property(wm => wm.CityName, m => m.CityModel.IfNotNull(p => p.Name))
                    .Property(wm => wm.Fullname, m => $"{m.Family} {m.Name}");
            });

Yoc can use "Ignore" functions:

Mapper.MapConfiguration(cfg =>
            {
                cfg.CreateMap<StudentModel, Dto.StudentModel>()
                    .Ignore(nameof(Mock.MapModels.Base.StudentModelMock.CityName))
                    // Or You can use this style.
                    .Ignore(m => m.CityName)
            });

Then in your application code, execute the mappings:

 var dtoModel = Mapper.Convert<Dto.StudentModel>(student);

Datareader Configuration

Mapper.MapConfiguration(cfg =>
            {
                cfg.CreateDataReaderMap<Student>()
                    .Ignore(p => p.Birthday)
                    //// Or
                    //.Ignore(nameof(Student.Birthday))
                    .Property(p => p.FirstName, "Name")
                    .Property(p => p.LastName, "Family");
            });

If you have standart SQL Style Guide (first name becomes first_name) you can use "UseStandardCodeStyleForMembers()" function.

Mapper.MapConfiguration(cfg =>
            {
                cfg.CreateDataReaderMap<Student>()
                    .UseStandardCodeStyleForMembers();
            });

Or you can do it manually

Mapper.MapConfiguration(cfg =>
            {
                cfg.CreateDataReaderMap<Student>()
                    .Property(p => p.FirstName, "first_name")
                    .Property(p => p.LastName, "last_name");
            });

About

A convention object to object or DataReader to object mapper in .NET Core 2.0.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%