我有这个转换器类。
public class StatsConverter : TypeConverter<Tuple<Player,Stats>, StatsModel>
, ITypeConverter<Stats, StatsModel>
{
protected override StatsModel ConvertCore(Tuple<Player, Stats> source)
{
var pm = new StatsModel
{
Id = source.Item2.Id,
PlayerId = source.Item1.Id,
DisplayName = source.Item2.DisplayName,
};
return pm;
}
}
在我有----需要映射IEnumerable<StatsModel>
的以下场景中,我如何返回?List
player.PlayerStats
[HttpGet("{id:int}/PlayerStats", RouteName = "GetPlayerStats")]
public IEnumerable<StatsModel> GetPlayerStats(int id)
{
var user = this._manager.GetPlayerById(id);
// I can retrieve a "List" of player.PlayerStats.
//But how do I map and return it?
return this._mapper.Map<IEnumerable<StatsModel>>(????)
}
当我这样做时
return this._mapper.Map<IEnumerable<StatsModel>>(player.PlayerStats);
我得到这个错误:
Change the type converter source type, or redirect the source value supplied to the value resolver using FromMember
。