ITypeConverter interface has been changed in AutoMapper 2.0

744 views
Skip to first unread message

Kiquenet.com

unread,
Nov 17, 2011, 10:10:59 AM11/17/11
to AutoMapper-users
Does anybody know of a guide on migration to 0.4 to 2.0 version using
ITypeConverter ?

The ITypeConverter interface has been changed to have a "TDestination
Convert(ResolutionContext context)" instead of "TDestination
Convert(TSource source)" for the Convert method.

http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters

In my code, now I get this error:

'BusinessFacade.Mappers.DecimalToNullableInt' does not implement
interface member
'AutoMapper.ITypeConverter.Convert(AutoMapper.ResolutionContext)'

Any good full sample for new mapper like my mappers ? I don't want
change any code (or minimum code) in my projects...

My mapper now, I need "migrating.."

public class DecimalToNullableInt : ITypeConverter<decimal, int?>
{
public int? Convert(decimal source)
{
if (source == 0)
return null;
return (int)source;
}
}


I'm sure there are many more things which should be taken into
consideration so I'm hoping that an AutoMapper expert has written up
something, somewhere, that I can leverage.



http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters
https://github.com/AutoMapper/AutoMapper/wiki/Custom-type-converters

The ITypeConverter interface has been changed to have a "TDestination
Convert(ResolutionContext context)" instead of "TDestination
Convert(TSource source)" for the Convert method.



Thanks.


Jimmy Bogard

unread,
Nov 17, 2011, 11:26:35 AM11/17/11
to automapp...@googlegroups.com
If you inherit from TypeConverter instead of ITypeConverter, you're almost there. Then it's just overriding a method instead of implementing the interface.

The interface change was there to support being able to access contextual information beyond just the source object.

Thanks,

Jimmy



--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To post to this group, send email to automapp...@googlegroups.com.
To unsubscribe from this group, send email to automapper-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.


Reply all
Reply to author
Forward
0 new messages