Как мне обновить этот TypeConverter, чтобы использовать последнюю версию AutoMapper? - PullRequest
0 голосов
/ 24 октября 2018

Я пытаюсь обновить код, который я не написал из AutoMapper 4.0.4, до 7.0.1, и у меня возникла проблема.Существует TypeConverter, который выглядит следующим образом:

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);
...

Но интерфейсы ITypeConverter и ResolutionContext теперь изменились.ResolutionContext больше не имеет свойств SourceValue, DestinationValue, PropertyMap или Parent.Я подумал, что поскольку новая сигнатура метода Covert имеет параметры для исходных и целевых объектов, я мог бы просто пропустить первый оператор if, например:

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)
    {
...

Но параметр destinationListприходит как null, так что, очевидно, мне все еще нужна логика, которую делает оператор if, но как мне переписать его для AutoMapper 7?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...