这些是我想要映射的类:
BasicOvervIEw{ public IRichTextContent Intro { get; set; } ...}BlogovervIEwviewmodel{ public IRichTextContent Intro { get; set; } ...}
以下是定义IRichTextContent类型的第三方代码:
// Represents rich text content in a form of structured datapublic interface IRichTextContent : IEnumerable<IRichTextBlock>,IEnumerable{ // // Summary: // List of rich text content blocks IEnumerable<IRichTextBlock> Blocks { get; set; }}
我的automapper配置文件:
public automapperProfile() { CreateMap<BasicOvervIEw,BlogListviewmodel>(); CreateMap<BasicOvervIEw,RevIEwListviewmodel>(); CreateMap<BasicOvervIEw,BlogovervIEwviewmodel>(); }
这是我得到的错误:
An unhandled exception occurred while processing the request.
InvalIDCastException: Unable to cast object of type ‘System.Collections.Generic.List`1[KenticoCloud.Delivery.IRichTextBlock]’ to type ‘KenticoCloud.Delivery.IRichTextContent’.
lambda_method(Closure,BasicOvervIEw,BlogovervIEwviewmodel,ResolutionContext )autoMapperMapPingException: Error mapPing types.
MapPing types:
BasicOvervIEw -> BlogovervIEwviewmodelType Map configuration:
BasicOvervIEw -> BlogovervIEwviewmodelDestination Member:
Intro
lambda_method(Closure,ResolutionContext )
我尝试将以下内容添加到我的automapper配置文件中:
CreateMap<IEnumerable<IRichTextBlock>,IRichTextContent>() .ForMember(dest => dest.Blocks,m => m.MapFrom(src => src));
其中产生了以下错误:
解决方法 只是为了让 Lucian Bargaoanu的评论更加明显.TypeLoadException: Method ‘GetEnumerator’ in type ‘Proxy_KenticoCloud.Delivery.IRichTextContent_12345678_’ from assembly ‘autoMapper.ProxIEs,Version=0.0.0.0,Culture=neutral,PublicKeyToken=abc123ef45’ does not have an implementation.
其中一个解决方案是将以下映射添加到automapper配置文件:
CreateMap<IRichTextContent,IRichTextContent>().ConvertUsing(s=>s);总结
以上是内存溢出为你收集整理的c# – 防止Automapper将IEnumerable属性转换为List全部内容,希望文章能够帮你解决c# – 防止Automapper将IEnumerable属性转换为List所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)