//============================================================ // 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 //------------------------------------------------------------ AtomContent value = obj as AtomContent; if (value != null) { int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.ContentType, value.ContentType, StringComparison.OrdinalIgnoreCase); result = result | Uri.Compare(this.Source, value.Source, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | AtomUtility.CompareCommonObjectAttributes(this, value); 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); } AtomContent value = obj as AtomContent; if (value != null) { int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.ContentType, value.ContentType, StringComparison.OrdinalIgnoreCase); result = result | Uri.Compare(this.Source, value.Source, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | AtomUtility.CompareCommonObjectAttributes(this, value); 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> /// Creates a <see cref="AtomContent"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <returns>A <see cref="AtomContent"/> instance initialized using the supplied <paramref name="source"/>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 Content construct. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static AtomContent CreateContent(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomContent content = new AtomContent(); string modeAttribute = String.Empty; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ AtomUtility.FillCommonObjectAttributes(content, source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); modeAttribute = source.GetAttribute("mode", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { content.ContentType = typeAttribute; } } if (String.Compare(modeAttribute, "xml", StringComparison.OrdinalIgnoreCase) == 0) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { content.Content = xhtmlDivNavigator.Value; } else if (!String.IsNullOrEmpty(source.Value)) { content.Content = source.Value; } } else if (!String.IsNullOrEmpty(source.Value)) { content.Content = source.Value; } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(content, manager); return content; }