我正在尝试反序列化iCal文件,然后将集合映射到自定义POCO.问题是我不确定属性的存储位置.
这是反序列化方法
public static IICalendarCollection Deserialize(String iCalUri)
{
var wc = new WebClient();
var result = wc.DownloadString(iCalUri);
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(result)))
{
var serializer = new iCalendarSerializer();
var collection = (iCalendarCollection)serializer.Deserialize(memoryStream, Encoding.UTF8);
return collection;
}
}
然后在我的服务中,我试图将属性映射到我的POCO,但我找不到属性.
var url = string.Format(GoogleICalUrl, calendarID);
var feed = iCalUtility.Deserialize(url);
foreach(var e in feed)
{
calendarModel.title = e.WhereTheHellAreThePropertiesKept;
}
有没有人知道循环通过iCalendarCollection并获得所有属性的正确方法?
我检查了DDay网站,但它一整天都在关闭.
最佳答案 经过一番挖掘后,事实证明IICalendarCollection有一个嵌套的Event集合需要解析如下.
var url = string.Format(GoogleICalUrl, calendarID);
var feed = iCalUtility.Deserialize(url);
foreach (var ev in feed.SelectMany(e => e.Events))
{
calendarModel.Add(new CalendarModel {description = ev.Description,
title = ev.Summary});
}