Replace member names with Mapper.Initialize #479

wants to merge 4 commits into

3 participants


As discussed in issue #471 member names can be partly invalid due to spelling, language or other reasons.

This submit can help you map rules to those bad naming conventions.

            public class Source
                public int Value { get; set; }
                public int Ävíator { get; set; }
                public int SubAirlinaFlight { get; set; }

            public class Destination
                public int Value { get; set; }
                public int Aviator { get; set; }
                public int SubAirlineFlight { get; set; }

            Mapper.Initialize(c =>
                c.ReplaceMemberName("Ä", "A");
                c.ReplaceMemberName("í", "i");
                c.ReplaceMemberName("Airlina", "Airline");

            var source = new Source()
                Value = 5,
                Ävíator = 3,
                SubAirlinaFlight = 4

            Mapper.CreateMap<Source, Destination>();
            var destination = Mapper.Map<Source, Destination>(source);

            Assert.Equal(source.Value, destination.Value);
            Assert.Equal(source.Ävíator, destination.Aviator);
            Assert.Equal(source.SubAirlinaFlight, destination.SubAirlineFlight);
kobbikobb added some commits Mar 12, 2014
@kobbikobb kobbikobb MemberNameReplacers
Match member names with replaced member names.

Issue: #471

//Mapping from:
class DemoLegacyModel
public int Äviator { get; set: }

class DemoViewModel
public int Aviator { get; set: }
@kobbikobb kobbikobb Found a better name in settings
var mappingOptions = new StubMappingOptions();
mappingOptions.ReplaceMemberName("Ä", "A");
mappingOptions.ReplaceMemberName("í", "i");
mappingOptions.ReplaceMemberName("Airlina", "Airline");
@kobbikobb kobbikobb Mapper.Configuration
Replacer code for Mapper.Configuration implemented and tests refactored.
@kobbikobb kobbikobb Test was not complete
I was running the wrong test.
@jbogard jbogard added the Feature label Apr 24, 2014
@jbogard jbogard added this to the 3.3.0 milestone Apr 24, 2014
@jbogard jbogard added a commit that closed this pull request Sep 4, 2014
@jbogard jbogard Merge branch 'kobbikobb-develop' into develop
Closes #479
Closes #471
@jbogard jbogard closed this in 6b9622b Sep 4, 2014

Those code didn't work in my VS2013 Console program,is it a bug?

Mapper.Initialize(cfg =>
            cfg.ReplaceMemberName("Ä", "A");
            cfg.ReplaceMemberName("í", "i");

 public class AliensPersonProfile : Profile
        protected override void Configure()
            //SourceMemberNamingConvention=new LowerUnderscoreNamingConvention();
            //DestinationMemberNamingConvention=new PascalCaseNamingConvention();

 var p2 = Mapper.Map<Person>(new Aliens() { Ävíator = 3 });

The result is not 3 but 0.Why?


I know the reason,I should put the "ReplaceMemberName" before "AddProfile();"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment