Exemplo n.º 1
0
        public static bool TryFormatRss10SyndicationExtension(Rss10SyndicationExtension extensionToFormat, XNamespaceAliasSet namespaceAliases, out IList <XElement> elements)
        {
            elements = default;

            if (extensionToFormat == null)
            {
                return(false);
            }

            elements = new List <XElement>();

            if (TryFormatRss10SyndicationUpdatePeriod(extensionToFormat.UpdatePeriod, namespaceAliases, out var updatePeriodElement))
            {
                elements.Add(updatePeriodElement);
            }

            if (TryFormatRss10SyndicationUpdateFrequency(extensionToFormat.UpdateFrequency, namespaceAliases, out var updateFrequencyElement))
            {
                elements.Add(updateFrequencyElement);
            }

            if (TryFormatRss10SyndicationUpdateBase(extensionToFormat.UpdateBase, namespaceAliases, out var updateBaseElement))
            {
                elements.Add(updateBaseElement);
            }

            if (!elements.Any())
            {
                return(false);
            }

            return(true);
        }
        public static bool TryParseRss10SyndicationExtension(XElement channelElement, out Rss10SyndicationExtension extension)
        {
            extension = null;

            if (channelElement == null)
            {
                return(false);
            }

            foreach (var ns in Rss10SyndicationExtensionConstants.RecognizedNamespaces)
            {
                if (TryParseRss10SyndicationUpdatePeriod(channelElement.Element(ns + "updatePeriod"), out var parsedUpdatePeriod))
                {
                    extension = extension ?? new Rss10SyndicationExtension();
                    extension.UpdatePeriod = parsedUpdatePeriod;
                }

                if (TryParseRss10SyndicationUpdateFrequency(channelElement.Element(ns + "updateFrequency"), out var parsedUpdateFrequency))
                {
                    extension = extension ?? new Rss10SyndicationExtension();
                    extension.UpdateFrequency = parsedUpdateFrequency;
                }

                if (TryParseRss10SyndicationUpdateBase(channelElement.Element(ns + "updateBase"), out var parsedUpdateBase))
                {
                    extension            = extension ?? new Rss10SyndicationExtension();
                    extension.UpdateBase = parsedUpdateBase;
                }
            }

            return(extension != null);
        }