2

I have an issue with uppercase underscore mappings.

Data Class have property like => USER_ID

Dto class property => UserId

If a change it to Userİd it's working.

How could i do mapping without formember method ? Thanks

My initializer :

 cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
 cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();   

Edit:

I solved it for now. It worked for USER_ID => UserId

Main topic : Automapper: How to leverage a custom INamingConvention?

Solution with basic if :

public class UpperUnderscoreNamingConvention : INamingConvention
{
    private readonly Regex _splittingExpression = new Regex(@"[\p{Lu}0-9]+(?=_?)");

    public Regex SplittingExpression { get { return _splittingExpression; } }

    public string SeparatorCharacter { get { return "_"; } }

    public string ReplaceValue(Match match)
    {
       return match.Value.Equals("I") ? "ı" : match.Value.ToLowerInvariant();           
    }
}

config :

Mapper.Initialize(cfg =>
        {

            cfg.SourceMemberNamingConvention = new UpperUnderscoreNamingConvention();
            cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();                


        });
cod3r
  • 21
  • 1
  • 6
  • It looks like AutoMapper only supports pascal and underscore naming conventions as per [the docs](http://docs.automapper.org/en/latest/Configuration.html?highlight=DestinationMemberNamingConvention#naming-conventions). Is there some reason that you want to have it in the uppercase form? AutoMapper can be configured to apply transforms to property names. – Matt Stannett Jan 29 '18 at 09:26
  • Google [knows](https://www.google.ro/search?dcr=0&q=UpperUnderscoreNamingConvention&nfpr=1&sa=X&ved=0ahUKEwiMq6rp8fzYAhWBfiwKHWVlCWQQvgUIJCgB&biw=1920&bih=968) :) – Lucian Bargaoanu Jan 29 '18 at 09:46
  • You'll just have to take the LowerUnderscoreNamingConvention as a model, or find a newer implementation somewhere. – Lucian Bargaoanu Jan 29 '18 at 10:44

0 Answers0