Пример #1
0
        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>();
        }
Пример #2
0
        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")
            ;
        }
Пример #3
0
        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>();
        }
Пример #5
0
        public void Register(CodeGenerationConfig config)
        {
            config.AdaptTwoWays("[name]DTO", MapType.Map | MapType.MapToTarget | MapType.Projection)
            .ApplyDefaultRule();

            config.AdaptTwoWays("[name]DTO", MapType.Map | MapType.MapToTarget | MapType.Projection)
            .ForType <User>().IgnoreNoAttributes(typeof(DataMemberAttribute));

            config.GenerateMapper("[name]Mapper")
            .ForAllTypesInNamespace(Assembly.GetAssembly(typeof(BaseEntity)), "DAL.Entities");
        }