public void Register(CodeGenerationConfig config) { config.AdaptTo("[name]Dto", MapType.Map | MapType.MapToTarget | MapType.Projection) .ApplyDefaultRule() .AlterType <Student, Person>(); config.AdaptFrom("[name]Add", MapType.Map) .ApplyDefaultRule() .IgnoreNoModifyProperties(); config.AdaptFrom("[name]Update", MapType.MapToTarget) .ApplyDefaultRule() .IgnoreAttributes(typeof(KeyAttribute)) .IgnoreNoModifyProperties(); config.AdaptFrom("[name]Merge", MapType.MapToTarget) .ApplyDefaultRule() .IgnoreAttributes(typeof(KeyAttribute)) .IgnoreNoModifyProperties() .IgnoreNullValues(true); config.GenerateMapper("[name]Mapper") .ForType <Course>() .ForType <Student>(); }
public void Register(CodeGenerationConfig config) { //config.AdaptTo("[name]Dto") // .ForType<Student>(builder => // builder.Settings[nameof(Student.FirstMidName)].TargetPropertyType = typeof(string?)); //config.AdaptFrom("[name]Merge") // .ForType<Student>() // .IgnoreNullValues(true); //config.AdaptTo("[name]Dto").ForType<Enrollment>().MapToConstructor(true); //config.AdaptFrom("[name]Dto").ForType<Enrollment>(); config.AdaptTo("[name]Dto", MapType.Map | MapType.MapToTarget | MapType.Projection) .ForAllTypesInNamespace(Assembly.GetExecutingAssembly(), "MapsterTest.Domains") .MapToConstructor(true) .ShallowCopyForSameType(true) //浅拷贝 .ExcludeTypes(o => o.IsEnum || Nullable.GetUnderlyingType(o)?.IsEnum == true) .MaxDepth(3) //嵌套深度 .PreserveReference(true) //缓存 dto 对象 //.ForType<Student>(builder => builder.IsNullableReference(o => o.FirstMidName)) ; config.GenerateMapper("[name]Mapper") .ForAllTypesInNamespace(Assembly.GetExecutingAssembly(), "MapsterTest.Domains") ; }
public void Register(CodeGenerationConfig config) { config.AdaptTo("[name]ResultDto", MapType.Map | MapType.MapToTarget | MapType.Projection) .ApplyDefaultRule(); config.AdaptFrom("[name]Dto", MapType.Map) .ApplyDefaultRule(); }
public void Register(CodeGenerationConfig config) { var as1 = Assembly.Load("SeparateProject"); config.AdaptTo("[name]Dto") .ForAllTypesInNamespace(as1, "SeparateProject.Models"); config.GenerateMapper("[name]Mapper") .ForAllTypesInNamespace(as1, "SeparateProject.Models"); }
public void Register(CodeGenerationConfig config) { config.AdaptTo("[name]Dto", MapType.Map | MapType.MapToTarget | MapType.Projection) .ApplyDefaultRule(); config.GenerateMapper("[name]Mapper") .ForType <Product>() .ForType <Customer>() .ForType <Country>(); }
public void Register(CodeGenerationConfig config) { config.AdaptTo("[name]Dto") .ForAllTypesInNamespace(Assembly.GetExecutingAssembly(), "Kasp.ObjectMapper.Benchmark.Models"); }