Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automapper 5.0.0 missing SourceValue (Custom Converters)

Tags:

c#

automapper

After updating automapper version from 4.2.1 to 5.0.0 I got compilateion error that SourceValue is missing. Here is my example

 public class DraftLayoutCellPropertiesConverter : ITypeConverter<DraftLayoutCell, DraftGamePeriodDraftLayoutViewModel>
    {
        public DraftGamePeriodDraftLayoutViewModel Convert(ResolutionContext context)
        {
            var input = context.SourceValue as DraftLayoutCell;
            var result = new DraftGamePeriodDraftLayoutViewModel();

            if (input != null)
            {

What should be the replacement of that property? Is that the best way to do custom converters? I was expecting the update will not break existing code as there are many people using the app.

like image 507
Lyubomir Velchev Avatar asked Jul 05 '16 13:07

Lyubomir Velchev


1 Answers

In Automapper 5, The interface ITypeConverter changed, you need to update your implementation:

public class DraftLayoutCellPropertiesConverter : ITypeConverter<DraftLayoutCell, DraftGamePeriodDraftLayoutViewModel>
{
    public DraftGamePeriodDraftLayoutViewModel Convert(DraftLayoutCell source, DraftGamePeriodDraftLayoutViewModel destination, ResolutionContext context)
    {
        var input = source;
        ...
    }
}
like image 79
K. R. Avatar answered Sep 30 '22 10:09

K. R.