private void SerializeProperties(SyndicationItemBase item, XmlWriter writer) { if (!string.IsNullOrEmpty(item.Id)) { writer.WriteElementString("id", item.Id); } if (!string.IsNullOrEmpty(item.Id)) { writer.WriteStartElement("title"); writer.WriteAttributeString("type", "text"); writer.WriteValue(item.Title); writer.WriteEndElement(); } if (item.PublishDate.HasValue) { writer.WriteElementString("published", item.PublishDate.Value.ToString("u")); } if (item.LastUpdatedTime.HasValue) { writer.WriteElementString("updated", item.LastUpdatedTime.Value.ToString("u")); } if (item.SelfLink != null) { writer.WriteStartElement("link"); writer.WriteAttributeString("rel", "self"); writer.WriteAttributeString("href", item.SelfLink.ToString()); writer.WriteEndElement(); } }
private void DeserializeProperty(XmlReader reader, SyndicationItemBase item) { switch (reader.Name) { case "id": item.Id = reader.ReadElementContentAsString(); break; case "title": item.Title = reader.ReadElementContentAsString(); break; case "published": item.PublishDate = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString()); break; case "updated": item.LastUpdatedTime = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString()); break; case "author": reader.ReadToDescendant("name"); item.Author = reader.ReadElementContentAsString(); break; case "link": var rel = reader.GetAttribute("rel"); if (rel == "self") { var href = reader.GetAttribute("href"); Uri linkUri = null; var isAbsoluteUri = Uri.TryCreate(href, UriKind.RelativeOrAbsolute, out linkUri); if (!isAbsoluteUri) { linkUri = new Uri(href, UriKind.Relative); } item.SelfLink = linkUri; } break; } }