In the project I'm working on, we map auto-generated DTOs to business objects. The database has ahem an unusual (but largely consistent) naming convention, which means that you can convert most DTO property names to their equivalent business object property names, thereby preserving many lines of code.
For example, in the DTO (and the database) we have a property called account_ID__createdthat will map to the BO property called CreatedAccountId. This is what happens in MemberNameTransformer.GetBoMemberName(), so it is not as simple as a slightly different agreement with another separator.
Following what I have in AutoMapper source code, I have this as my best guess:
public class DtoBoMappingOptions : IMappingOptions
{
public INamingConvention SourceMemberNamingConvention
{
get { return new PascalCaseNamingConvention(); }
set { throw new NotImplementedException(); }
}
public INamingConvention DestinationMemberNamingConvention
{
get { return new PascalCaseNamingConvention(); }
set { throw new NotImplementedException(); }
}
public Func<string, string> SourceMemberNameTransformer
{
get { return s => s; }
set { throw new NotImplementedException(); }
}
public Func<string, string> DestinationMemberNameTransformer
{
get { return MemberNameTransformer.GetBoMemberName; }
set { throw new NotImplementedException(); }
}
}
Now, how do you tell Mapper to use these options when matching SomeDto to SomeBusinessClass? I understand that I may have the wrong interface in IMappingOptions. The real meat of what I'm trying to accomplish is in MemeberNameTransformer.GetBoMemberName().
Extra credit: How do I tell Mapper to use these options when matching any IDto with IBusinessObject?
source
share