I am trying to use AutoMapper to pass data from a class with prefixes before property names and map it to a second class that does not have these prefixes. However, I don’t necessarily want him to always highlight this prefix: I just want him to do this for this particular mapping.
My source class is as follows:
public class AdvancedSearchFilterDataModel
{
public string ServiceMeterNumber { get; set; }
}
My target class is as follows:
[DataContract]
public class ServicesAdvancedSearchFilterData : AdvancedSearchFilterData
{
[DataMember]
public string MeterNumber { get; set; }
}
When I try to match such values, it works:
Mapper.Configuration.RecognizePrefixes("Service");
Mapper.CreateMap<AdvancedSearchFilterDataModel, ServicesAdvancedSearchFilterData>();
ServicesAdvancedSearchFilterData servciesFilterData =
Mapper.Map<ServicesAdvancedSearchFilterData>(model);
But I want the "Service" to be considered a prefix for certain mappings, as it is also used as a regular part of property names in other mappings. I tried to handle this profile, but it did not work - the data was not displayed:
Mapper.CreateProfile("ServicePrefix").RecognizePrefixes("Service");
Mapper.CreateMap<AdvancedSearchFilterDataModel, ServicesAdvancedSearchFilterData>()
.WithProfile("ServicePrefix");
ServicesAdvancedSearchFilterData servciesFilterData =
Mapper.Map<ServicesAdvancedSearchFilterData>(model);
, , ? ( , .)