//============================================================ // 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 //------------------------------------------------------------ LiveJournalSecurity value = obj as LiveJournalSecurity; if (value != null) { int result = this.Accessibility.CompareTo(value.Accessibility); result = this.Mask.CompareTo(value.Mask); 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> /// Saves the current <see cref="LiveJournalSecurity"/> to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public void WriteTo(XmlWriter writer) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); //------------------------------------------------------------ // Create extension instance to retrieve XML namespace //------------------------------------------------------------ LiveJournalSyndicationExtension extension = new LiveJournalSyndicationExtension(); //------------------------------------------------------------ // Write XML representation of the current instance //------------------------------------------------------------ writer.WriteStartElement("security", extension.XmlNamespace); writer.WriteAttributeString("type", LiveJournalSecurity.AccessibilityAsString(this.Accessibility)); if (this.Mask != Int32.MinValue) { writer.WriteAttributeString("mask", this.Mask.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } writer.WriteEndElement(); }
/// <summary> /// Loads this <see cref="LiveJournalSecurity"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="LiveJournalSecurity"/> 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="LiveJournalSecurity"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); string maskAttribute = source.GetAttribute("mask", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { LiveJournalSecurityType accessLevel = LiveJournalSecurity.AccessibilityByName(typeAttribute); if (accessLevel != LiveJournalSecurityType.None) { this.Accessibility = accessLevel; wasLoaded = true; } } if (!String.IsNullOrEmpty(maskAttribute)) { int mask; if (Int32.TryParse(maskAttribute, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out mask)) { this.Mask = mask; wasLoaded = true; } } } return(wasLoaded); }
/// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="LiveJournalSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="LiveJournalSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <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> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); if (source.HasChildren) { XPathNavigator musicNavigator = source.SelectSingleNode("lj:music", manager); XPathNavigator moodNavigator = source.SelectSingleNode("lj:mood", manager); XPathNavigator securityNavigator = source.SelectSingleNode("lj:security", manager); XPathNavigator userPictureNavigator = source.SelectSingleNode("lj:userpic", manager); XPathNavigator preformattedNavigator = source.SelectSingleNode("lj:preformatted", manager); if (musicNavigator != null && !String.IsNullOrEmpty(musicNavigator.Value)) { this.Music = musicNavigator.Value; wasLoaded = true; } if (moodNavigator != null) { LiveJournalMood mood = new LiveJournalMood(); if (mood.Load(moodNavigator)) { this.Mood = mood; wasLoaded = true; } } if (securityNavigator != null) { LiveJournalSecurity security = new LiveJournalSecurity(); if (security.Load(securityNavigator)) { this.Security = security; wasLoaded = true; } } if (userPictureNavigator != null) { LiveJournalUserPicture userPicture = new LiveJournalUserPicture(); if (userPicture.Load(userPictureNavigator)) { this.UserPicture = userPicture; wasLoaded = true; } } if (preformattedNavigator != null) { this.IsPreformatted = true; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Saves the current <see cref="LiveJournalSecurity"/> to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public void WriteTo(XmlWriter writer) { Guard.ArgumentNotNull(writer, "writer"); LiveJournalSyndicationExtension extension = new LiveJournalSyndicationExtension(); writer.WriteStartElement("security", extension.XmlNamespace); writer.WriteAttributeString("type", LiveJournalSecurity.AccessibilityAsString(this.Accessibility)); if (this.Mask != Int32.MinValue) { writer.WriteAttributeString("mask", this.Mask.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } writer.WriteEndElement(); }
/// <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); } LiveJournalSecurity value = obj as LiveJournalSecurity; if (value != null) { int result = this.Accessibility.CompareTo(value.Accessibility); result = this.Mask.CompareTo(value.Mask); 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"); } }