Reputation: 440
In these 3 classes, how do you map SourceString
to DestinationString
?
public class MySourceClass
{
public AnotherClass AnotherClass { get; set; }
}
public class AnotherClass
{
public string SourceString { get; set; }
}
// [AutoMap(typeof(MySourceClass))] // <--this doesn't seem to help
public class MyDestinationClass
{
//[SourceMember( nameof(AnotherClass.SourceString) )] <--not a winner
public string DestinationString { get; set; } // <-- this should map to AnotherClass.SourceString
}
If there were a way to do this in the CreateMap
method, it seems like a better place to keep the logic. Any help is appreciated!
Upvotes: 0
Views: 432
Reputation: 1133
On your automapper configuration you need to create a map for the 2 classes, because the properties are with different names you should add specific map.
CreateMap<AnotherClass , MyDestinationClass>()
.ForMember(x => x.DestinationString, x => x.ResolveUsing(y => y.SourceString));
Upvotes: 1