//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ GenericSyndicationItem value = obj as GenericSyndicationItem; if (value != null) { int result = GenericSyndicationFeed.CompareSequence(this.Categories, value.Categories); result = result | String.Compare(this.Summary, value.Summary, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { if (obj == null) { return(1); } GenericSyndicationItem value = obj as GenericSyndicationItem; if (value != null) { int result = GenericSyndicationFeed.CompareSequence(this.Categories, value.Categories); result = result | String.Compare(this.Summary, value.Summary, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="AtomFeed"/>. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(AtomFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Atom; if (feed.Title != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedTitle = feed.Title.Content; } if (feed.Subtitle != null && !String.IsNullOrEmpty(feed.Title.Content)) { feedDescription = feed.Subtitle.Content; } if (feed.UpdatedOn != DateTime.MinValue) { feedLastUpdatedOn = feed.UpdatedOn; } if(feed.Language != null) { feedLanguage = feed.Language; } foreach(AtomCategory category in feed.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach(AtomEntry entry in feed.Entries) { GenericSyndicationItem genericItem = new GenericSyndicationItem(entry); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }
/// <summary> /// Initializes the generic syndication feed using the supplied <see cref="RssFeed"/>. /// </summary> /// <param name="feed">The <see cref="RssFeed"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> is a null reference (Nothing in Visual Basic).</exception> public void Parse(RssFeed feed) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); //------------------------------------------------------------ // Initialize generic feed //------------------------------------------------------------ feedResource = feed; feedFormat = SyndicationContentFormat.Rss; if (!String.IsNullOrEmpty(feed.Channel.Title)) { feedTitle = feed.Channel.Title; } if (!String.IsNullOrEmpty(feed.Channel.Description)) { feedDescription = feed.Channel.Description; } if (feed.Channel.LastBuildDate != DateTime.MinValue) { feedLastUpdatedOn = feed.Channel.LastBuildDate; } if (feed.Channel.Language != null) { feedLanguage = feed.Channel.Language; } foreach (RssCategory category in feed.Channel.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); feedCategories.Add(genericCategory); } foreach (RssItem item in feed.Channel.Items) { GenericSyndicationItem genericItem = new GenericSyndicationItem(item); ((Collection<GenericSyndicationItem>)feedItems).Add(genericItem); } }