示例#1
0
        private static bool TryParseRssAtom10Link(XElement linkElement, out Atom10Link parsedLink)
        {
            parsedLink = default;

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

            parsedLink = new Atom10Link();

            parsedLink.Href     = linkElement.Attribute("href")?.Value;
            parsedLink.Hreflang = linkElement.Attribute("hreflang")?.Value;

            parsedLink.Rel   = linkElement.Attribute("rel")?.Value ?? "alternate";
            parsedLink.Title = linkElement.Attribute("title")?.Value;
            parsedLink.Type  = linkElement.Attribute("type")?.Value;

            if (int.TryParse(linkElement.Attribute("length")?.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var parsedLength))
            {
                parsedLink.Length = parsedLength;
            }

            return(true);
        }
        private static bool TryFormatRssAtom10Link(Atom10Link linkToFormat, XNamespaceAliasSet namespaceAliases, out XElement linkElement)
        {
            linkElement = default;

            if (string.IsNullOrEmpty(linkToFormat.Href))
            {
                return(false);
            }

            namespaceAliases.EnsureNamespaceAlias(RssAtom10ExtensionConstants.NamespaceAlias, RssAtom10ExtensionConstants.Namespace);
            linkElement = new XElement(RssAtom10ExtensionConstants.Namespace + "link");

            linkElement.Add(new XAttribute("href", linkToFormat.Href));

            if (TryFormatRssAtom10OptionalTextAttribute(linkToFormat.Rel, "rel", out var relAttribute))
            {
                linkElement.Add(relAttribute);
            }

            if (TryFormatRssAtom10OptionalTextAttribute(linkToFormat.Type, "type", out var typeAttribute))
            {
                linkElement.Add(typeAttribute);
            }

            if (TryFormatRssAtom10OptionalTextAttribute(linkToFormat.Hreflang, "hreflang", out var hreflangAttribute))
            {
                linkElement.Add(hreflangAttribute);
            }

            if (TryFormatRssAtom10OptionalTextAttribute(linkToFormat.Title, "title", out var titleAttribute))
            {
                linkElement.Add(titleAttribute);
            }

            if (TryFormatRssAtom10OptionalNumericAttribute(linkToFormat.Length, "length", out var lengthAttribute))
            {
                linkElement.Add(lengthAttribute);
            }

            return(true);
        }
示例#3
0
        private static bool TryFormatAtom10Link(Atom10Link linkToFormat, out XElement linkElement)
        {
            linkElement = default;

            if (string.IsNullOrEmpty(linkToFormat.Href))
            {
                return(false);
            }

            linkElement = new XElement(_atom + "link");

            linkElement.Add(new XAttribute("href", linkToFormat.Href));

            if (TryFormatAtom10OptionalTextAttribute(linkToFormat.Rel, "rel", out var relAttribute))
            {
                linkElement.Add(relAttribute);
            }

            if (TryFormatAtom10OptionalTextAttribute(linkToFormat.Type, "type", out var typeAttribute))
            {
                linkElement.Add(typeAttribute);
            }

            if (TryFormatAtom10OptionalTextAttribute(linkToFormat.Hreflang, "hreflang", out var hreflangAttribute))
            {
                linkElement.Add(hreflangAttribute);
            }

            if (TryFormatAtom10OptionalTextAttribute(linkToFormat.Title, "title", out var titleAttribute))
            {
                linkElement.Add(titleAttribute);
            }

            if (TryFormatAtom10OptionalNumericAttribute(linkToFormat.Length, "length", out var lengthAttribute))
            {
                linkElement.Add(lengthAttribute);
            }

            return(true);
        }