/// <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 //------------------------------------------------------------ AtomAcceptedMediaRange value = obj as AtomAcceptedMediaRange; if (value != null) { int result = String.Compare(this.MediaRange, value.MediaRange, 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); } AtomAcceptedMediaRange value = obj as AtomAcceptedMediaRange; if (value != null) { int result = String.Compare(this.MediaRange, value.MediaRange, 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> /// Loads this <see cref="AtomMemberResources"/> using the supplied <see cref="IXPathNavigable"/>. /// </summary> /// <param name="source">The <see cref="IXPathNavigable"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomMemberResources"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomMemberResources"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public override bool Load(IXPathNavigable source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XPathNavigator navigator = source.CreateNavigator(); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(navigator.NameTable); if (AtomUtility.FillCommonObjectAttributes(this, navigator)) { wasLoaded = true; } if (navigator.HasAttributes) { string hrefAttribute = navigator.GetAttribute("href", String.Empty); if (!String.IsNullOrEmpty(hrefAttribute)) { Uri href; if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href)) { this.Uri = href; wasLoaded = true; } } } if (navigator.HasChildren) { XPathNavigator titleNavigator = navigator.SelectSingleNode("atom:title", manager); XPathNodeIterator acceptIterator = navigator.Select("app:accept", manager); XPathNodeIterator categoriesIterator = navigator.Select("app:categories", manager); if (titleNavigator != null) { this.Title = new AtomTextConstruct(); if (this.Title.Load(titleNavigator)) { wasLoaded = true; } } if (acceptIterator != null && acceptIterator.Count > 0) { while (acceptIterator.MoveNext()) { AtomAcceptedMediaRange mediaRange = new AtomAcceptedMediaRange(); if (mediaRange.Load(acceptIterator.Current)) { this.Accepts.Add(mediaRange); wasLoaded = true; } } } if (categoriesIterator != null && categoriesIterator.Count > 0) { while (categoriesIterator.MoveNext()) { AtomCategoryDocument categories = new AtomCategoryDocument(); categories.Load(categoriesIterator.Current); wasLoaded = true; } } } return(wasLoaded); }