private static bool TryFormatMediaRssThumbnail(MediaRssThumbnail thumbnailToFormat, out XElement thumbnailElement) { thumbnailElement = default; if (string.IsNullOrEmpty(thumbnailToFormat?.Url)) { return(false); } thumbnailElement = new XElement(_media + "thumbnail", new XAttribute("url", thumbnailToFormat.Url)); if (thumbnailToFormat.Height != null) { thumbnailElement.Add(new XAttribute("height", thumbnailToFormat.Height.Value.ToString(CultureInfo.InvariantCulture))); } if (thumbnailToFormat.Width != null) { thumbnailElement.Add(new XAttribute("width", thumbnailToFormat.Width.Value.ToString(CultureInfo.InvariantCulture))); } if (Rfc2326NptTimeSpanFormatter.TryFormatTimeAsString(thumbnailToFormat.Time, out var timeFormatted)) { thumbnailElement.Add(new XAttribute("time", timeFormatted)); } return(true); }
private static bool TryParseMediaRssThumbnail(XElement thumbnailElement, out MediaRssThumbnail parsedThumbnail) { parsedThumbnail = default; if (!TryParseStringAttribute(thumbnailElement?.Attribute("url"), out var parsedUrl)) { return(false); } parsedThumbnail = new MediaRssThumbnail { Url = parsedUrl, }; if (TryParseIntegerAttribute(thumbnailElement?.Attribute("height"), out var parsedHeight)) { parsedThumbnail.Height = parsedHeight; } if (TryParseIntegerAttribute(thumbnailElement?.Attribute("width"), out var parsedWidth)) { parsedThumbnail.Width = parsedWidth; } if (TryParseTimeSpanAttribute(thumbnailElement?.Attribute("time"), out var parsedTime)) { parsedThumbnail.Time = parsedTime; } return(true); }