Я пытаюсь очистить строку EmailInstructions
во время сопоставления, но она не срабатывает, когда я вызываю Mapper.Configuration.AssertConfigurationIsValid();
с:
No coercion operator is defined between types 'System.String' and 'ElectionViewModel'
Вот мои настройки:
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(x =>
{
x.AddProfile<SystemProfile>();
});
Mapper.Configuration.AssertConfigurationIsValid();
}
}
My Mapper:
public class SystemProfile : Profile
{
public SystemProfile()
{
CreateMap<ElectionViewModel, Election>()
.ForMember(x => x.EmailInstructions, y =>
y.ConvertUsing(new EmailInstructionVariablesCleanerConverter()))
My ValueConverter
public class EmailInstructionVariablesCleanerConverter : IValueConverter<ElectionViewModel, string>
{
public string Convert(ElectionViewModel source, ResolutionContext context)
{
return CleanVariables(source.EmailInstructions);
}
private static string CleanVariables(string text)
{
return Clean the text here
}
}