我正在尝试转换一组匿名对象,其中每个对象如下所示:
new {type="internal",title="Linktitle",target="_blank",link="http://www.google.se"}
我已经声明了一个类“链接”,匿名对象应该被投射到该类
class Link{
public string type {get;set;}
public string target {get;set;}
public string title {get;set;}
public string link {get;set;}
}
现在我正在尝试投射对象,就像这样
List<Link> links = Model.relatedLinks.Select(l => new Link{type=l.type,target=l.target,title=l.title,link=l.link}).ToList();
然后我得到错误
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
我发现this page on how to cast anonymous objects,但我也是这样做的。还是我错过了什么?