In the project I'm working on, we are mapping auto-generated DTOs to business objects. The database has an ahem unusual (but largely consistent) naming convention, which means that it's possible to transform most DTO property names to their equivalent business object property names, thus saving many lines of code.
For example, in the DTO (and database) we have a property called account_ID__created
that will map to a BO property called CreatedAccountId
. This is the kind of transformation happening in MemberNameTransformer.GetBoMemberName()
, so it's not as simple as a slightly different convention with a different separator.
Following what I have available in the 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 I tell the Mapper to use these options when mapping SomeDto to SomeBusinessClass? I realize 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 the Mapper to use these options when mapping any IDto to IBusinessObject?