Partial Aliases - Need to replace characters in member names #471

Closed
kobbikobb opened this Issue Mar 7, 2014 · 4 comments

Projects

None yet

2 participants

@kobbikobb

O have a legacy library with objects where some members have names with special characters. In my viewmodel I want those characters removed and replaced with other similar characters. For example Ä -> A, ä -> a, Ö -> ö ...

Here is a demo of hypothetical classes:

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

//to:
class DemoViewModel
    public int Aviator { get; set: }

Is this possible with the current version?

If not, could we add something like:
RecognizePartialAlias("Ä", "A");
RecognizePartialAlias("ä", "a");
RecognizePartialAlias("Ö", "O");
RecognizePartialAlias("Ö", "o");
...

@kobbikobb

I actually cloned the repository and tried to implement this myself.

What I ended up with was:
cfg.ReplaceDestinationMemberName("Ä", "A");

In the FormatterExpression I added a HashSet of MemberNameReplacer which has the original value and the new value to be replaced at the destination.

Then in TypeNameFactory.NameMatches I added a string to the possibleDestNames enumeration which was created from the original value replaced by all the MemberNameReplacers.

To create a complete solution the same would have to be done for ReplaceSourceMemberName...

This is an Idea if someone on the team would be so good to add this functionality or something similar.

@jbogard
Member
jbogard commented Mar 10, 2014

I like this! Can you open a pull request?

On Fri, Mar 7, 2014 at 4:56 PM, Jakob Jónasson notifications@github.comwrote:

I actually cloned the repository and tried to implement this myself.

What I ended up with was:
cfg.ReplaceDestinationMemberName("Ä", "A");

In the FormatterExpression I added a HashSet of MemberNameReplacer which
has the original value and the new value to be replaced at the destination.

Then in TypeNameFactory.NameMatches I added a string to the
possibleDestNames enumeration which was created from the original value
replaced by all the MemberNameReplacers.

To create a complete solution the same whould have to be done for
ReplaceSourceMemberName...

This is an Idea if someone on the team would be so good to add this
functionality or something similar.

Reply to this email directly or view it on GitHubhttps://github.com/AutoMapper/AutoMapper/issues/471#issuecomment-37077156
.

This was referenced Mar 12, 2014
@kobbikobb

@jbogard

Here is a pull request.
ReplaceMemberNames #478

My change feels like a good contribution to the project.

I decided to have global replacers for both source and destination similar to Aliases.
I did not change any structure, just tried to fit my change in as if it had been there before.

How do you like this?
Any changes you would like to make?

Best Regards, Jakob

@kobbikobb

I did a few changes because my code was not complete and added test to show usage for Mapper.

@jbogard jbogard added this to the 3.3.0 milestone Jun 6, 2014
@jbogard jbogard added the Feature label Jun 6, 2014
@jbogard jbogard added a commit that referenced this issue Sep 4, 2014
@kobbikobb kobbikobb MemberNameReplacers
Match member names with replaced member names.

Issue: #471

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

//to:
class DemoViewModel
public int Aviator { get; set: }
2f708f6
@jbogard jbogard added a commit that closed this issue Sep 4, 2014
@jbogard jbogard Merge branch 'kobbikobb-develop' into develop
Closes #479
Closes #471
6b9622b
@jbogard jbogard closed this in 6b9622b Sep 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment