コード例 #1
0
        //============================================================
        //	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
            //------------------------------------------------------------
            SimpleListSort value = obj as SimpleListSort;

            if (value != null)
            {
                int result = this.DataType.CompareTo(value.DataType);
                result = result | String.Compare(this.Element, value.Element, StringComparison.OrdinalIgnoreCase);
                result = result | this.IsDefault.CompareTo(value.IsDefault);
                result = result | String.Compare(this.Label, value.Label, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Namespace, value.Namespace, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.Ordinal);

                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");
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the current <see cref="SimpleListSort"/> 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
            //------------------------------------------------------------
            SimpleListSyndicationExtension extension = new SimpleListSyndicationExtension();

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("sort", extension.XmlNamespace);

            if (this.Namespace != null)
            {
                writer.WriteAttributeString("ns", this.Namespace.ToString());
            }

            if (!String.IsNullOrEmpty(this.Element))
            {
                writer.WriteAttributeString("element", this.Element);
            }

            if (!String.IsNullOrEmpty(this.Label))
            {
                writer.WriteAttributeString("label", this.Label);
            }

            if (this.DataType != SimpleListDataType.None)
            {
                writer.WriteAttributeString("data-type", SimpleListSort.DataTypeAsString(this.DataType));
            }

            if (this.IsDefault)
            {
                writer.WriteAttributeString("default", "true");
            }

            writer.WriteEndElement();
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source, XmlNamespaceManager manager)
        /// <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="SimpleListSyndicationExtensionContext"/>.</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="SimpleListSyndicationExtensionContext"/> 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)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator treatAsNavigator         = source.SelectSingleNode("cf:treatAs", manager);
                XPathNavigator listInformationNavigator = source.SelectSingleNode("cf:listinfo", manager);

                if (treatAsNavigator != null && String.Compare(treatAsNavigator.Value, "list", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    this.TreatAsList = true;
                    wasLoaded        = true;
                }

                if (listInformationNavigator != null && listInformationNavigator.HasChildren)
                {
                    XPathNodeIterator sortIterator  = source.Select("cf:sort", manager);
                    XPathNodeIterator groupIterator = source.Select("cf:group", manager);

                    if (sortIterator != null && sortIterator.Count > 0)
                    {
                        while (sortIterator.MoveNext())
                        {
                            SimpleListSort sort = new SimpleListSort();
                            if (sort.Load(sortIterator.Current))
                            {
                                this.Sorting.Add(sort);
                                wasLoaded = true;
                            }
                        }
                    }

                    if (groupIterator != null && groupIterator.Count > 0)
                    {
                        while (groupIterator.MoveNext())
                        {
                            SimpleListGroup group = new SimpleListGroup();
                            if (group.Load(groupIterator.Current))
                            {
                                this.Grouping.Add(group);
                                wasLoaded = true;
                            }
                        }
                    }
                }
            }

            return(wasLoaded);
        }
コード例 #4
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="SimpleListSort"/> 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="SimpleListSort"/> 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="SimpleListSort"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string namespaceAttribute = source.GetAttribute("ns", String.Empty);
                string elementAttribute   = source.GetAttribute("element", String.Empty);
                string labelAttribute     = source.GetAttribute("label", String.Empty);
                string dataTypeAttribute  = source.GetAttribute("data-type", String.Empty);
                string defaultAttribute   = source.GetAttribute("default", String.Empty);

                if (!String.IsNullOrEmpty(namespaceAttribute))
                {
                    Uri elementNamespace;
                    if (Uri.TryCreate(namespaceAttribute, UriKind.RelativeOrAbsolute, out elementNamespace))
                    {
                        this.Namespace = elementNamespace;
                        wasLoaded      = true;
                    }
                }

                if (!String.IsNullOrEmpty(elementAttribute))
                {
                    this.Element = elementAttribute;
                    wasLoaded    = true;
                }

                if (!String.IsNullOrEmpty(labelAttribute))
                {
                    this.Label = labelAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(dataTypeAttribute))
                {
                    SimpleListDataType dataType = SimpleListSort.DataTypeByName(dataTypeAttribute);
                    if (dataType != SimpleListDataType.None)
                    {
                        this.DataType = dataType;
                        wasLoaded     = true;
                    }
                }

                if (!String.IsNullOrEmpty(defaultAttribute))
                {
                    if (String.Compare(defaultAttribute, "true", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsDefault = true;
                        wasLoaded      = true;
                    }
                    else if (String.Compare(defaultAttribute, "false", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsDefault = false;
                        wasLoaded      = true;
                    }
                }
            }

            return(wasLoaded);
        }