从VB.NET中的LINQ查询返回匿名类型

时间:2011-03-25 11:25:26

标签: asp.net xml linq

我正在使用转发器控件在我的网站上显示RSS源。我想知道在VB中是否有可能从我的linq查询中返回一个匿名类型,而不是强类型RSSItems的集合。我知道这在C#中是可行的,但是无法计算出VB等价物。

Public Class RSSItem
    Public Property Title As String
    Public Property Link As String
    Public Property Content As String
    Public Property Description As String
    Public Property pubDate As String
    Public Property category As String
End Class

    Dim feedXML As XDocument = XDocument.Load("http://myrssfeed.com/rss.xml")
    Dim xns As XNamespace = "http://purl.org/rss/1.0/modules/content/"

    Dim feeds = From feed In feedXML.Descendants("item") _
                Select New RSSItem With _
                       {.Title = feed.Element("title"),
                        .Link = feed.Element("link"),
                        .Content = feed.Element(xns.GetName("encoded")).Value,
                        .Description = feed.Element("description"),
                        .pubDate = feed.Element("pubDate"),
                        .category = GetCategories(feed.Elements("category"))}

1 个答案:

答案 0 :(得分:8)

我相信您可以将New RSSItem With更改为New With。有关详情,请参阅VB Anonymous Types MSDN page