我对大写下划线映射存在问题。
数据类具有类似=>的属性USER_ID
Dto class property =>用户ID
如果将其更改为Userİd它正在运行。
如何在没有成员方法的情况下进行映射? 感谢
我的初始化程序:
cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
编辑:
我现在解决了。它适用于USER_ID =>用户ID
主题:Automapper: How to leverage a custom INamingConvention?
基本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();
});