I'm trying to upgrade some code that I didn't write from AutoMapper 4.0.4 to 7.0.1 and I'm running into an issue. There is a TypeConverter that looks like this:
public class BaseListTypeConverter<TCol1, TCol2, T1, T2> : ITypeConverter<TCol1, TCol2>
where TCol1 : ICollection<T1>
where TCol2 : ICollection<T2>
where T1 : class
where T2 : class
{
public TCol2 Convert(ResolutionContext context)
{
var sourceList = (TCol1)context.SourceValue;
TCol2 destinationList = default(TCol2);
if (context.PropertyMap == null
|| context.Parent == null
|| context.Parent.DestinationValue == null)
destinationList = (TCol2)context.DestinationValue;
else
destinationList = (TCol2)context.PropertyMap.DestinationProperty.GetValue(context.Parent.DestinationValue);
...
But the ITypeConverter and ResolutionContext interfaces have now changed. The ResolutionContext no longer has the SourceValue
, DestinationValue
, PropertyMap
, or Parent
properties. I thought that since the new signature of the Covert
method has parameters for the source and destination objects that I could just omit the first if
statement as in:
public class BaseListTypeConverter<TCol1, TCol2, T1, T2> : ITypeConverter<TCol1, TCol2>
where TCol1 : ICollection<T1>
where TCol2 : ICollection<T2>
where T1 : class
where T2 : class
{
public TCol2 Convert(TCol1 sourceList, TCol2 destinationList, ResolutionContext context)
{
...
But the parameter destinationList
is coming in as null so apparently I still need whatever logic that if
statement is doing, but how do I rewrite it for AutoMapper 7?