1
我有我需要序列化的SyndicationItem對象的集合,但我不知道我如何去做這件事。建議?如何序列化SyndicationItem對象的集合?
IEnumberable<SyndicationItem> blogPosts = GetBlogPosts();
...
private IEnumerable<SyndicationItem> GetBlogPosts()
{
var query = Enumerable.Empty<SyndicationItem>();
foreach (string feed in Feeds)
{
try
{
using (XmlReader reader = XmlReader.Create(feed))
{
query = query.Union((from item in SyndicationFeed.Load(reader).Items
orderby item.PublishDate descending
select item).Take(NumberOfItemsToDisplay));
}
}
catch (Exception ex)
{
Console.WriteLine("Invalid Feed: {0} ({1})", feed, ex.Message);
}
}
query = query.OrderByDescending(i => i.PublishDate).Take(NumberOfItemsToDisplay);
return query;
}
感謝您的建議。雖然這確實有效,但我認爲這種方法對於我的需求是過分的。最後,我決定讓我的Linq查詢返回一組簡單的POCO對象,因爲我並不需要SyndicationItem提供的所有數據。 – eponymous23
如果我們需要SyndicationItem提供的所有數據,該怎麼辦? – Wingjam