我有一个问题,我的 List 到 Dictionary 的映射不会将 Name 映射到 Key 属性。价值做得很好。实现如下。System.ArgumentNullException: '值不能为空。参数名称:key'
执行
_mapper.Map<List<MetaModel>, Dictionary<string, object>>(model.MemberPaymentVendor.Meta)
配置
config.NewConfig<MetaModel, KeyValuePair<string, object>>()
.ConstructUsing(x => new KeyValuePair<string, object>(x.Name, x.Value));
config.NewConfig<List<MetaModel>, Dictionary<string, object>>()
.MapWith(s => ToDictionary<MetaModel>(s));
public static Dictionary<string, object> ToDictionary<T>(List<T> source)
{
if (source == null)
return new Dictionary<string, object>();
return source.Select(v => v.Adapt<KeyValuePair<string, object>>()).ToDictionary(k => k.Key, v => v.Value);
}