私の MVC Web アプリケーションでは、次のオートマッパー コードを取得しました。
設定:
public static void Configure()
{
Mapper.CreateMap<string, List<Ruimte>>().ConvertUsing<StringCombinatieRuimtesConverter>();
}
カスタム コンバーター:
public class StringCombinatieRuimtesConverter : ITypeConverter<string, List<Ruimte>>
{
#region Implementation of ITypeConverter<in string,out List<Ruimte>>
public List<Ruimte> Convert(ResolutionContext context)
{
if (context.SourceValue == null)
{
return new List<Ruimte>();
}
return context.SourceValue.ToString().Split(',').Select(r => new Ruimte { Id = int.Parse(r) }).ToList();
}
#endregion
}
そして、次のコードで呼び出します。
var ruimteList = new List<Ruimte>();
// Update the CombinatieVan
Mapper.Map(command.CombinatieRuimteVan, ruimteList);
If I debug the command.CombinatieRuimteVan is: 2,3,4,6. This is fine. Now if I debug the converter it does return 4 objects of the class "Ruimte" with as Id the numbers stated before. But after the Mapper.Map method is done the "ruimteList" is still an empty list.
Does anyone know what is going wrong here? The automapper works fine on another spot in my application where I automap a whole entity containing the "CombinatieRuimteVan" set. But when I sololy convert the string to the list it doesn't seem to work.