开发者

Return Anonymous type from LINQ query in VB.NET

I am consuming an RSS feed to display on my website using a repeater control. I was wondering if it's possible in VB to return an anonymous type from my linq query rather than a collection of strongly typed RSSItems. I know this is possible in C#, however haven't been able to work out a VB equivalent.

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") _
      开发者_JAVA百科          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"))}


I believe you can change New RSSItem With to New With. More details can be found in the VB Anonymous Types MSDN page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜