private static bool TryFormatMediaRssLocation(MediaRssLocation locationToFormat, XNamespaceAliasSet namespaceAliases, ExtensionManifestDirectory extensionManifestDirectory, out XElement locationElement) { locationElement = default; if (locationToFormat == null) { return(false); } var childObjects = new List <object>(); if (MinutesSecondsTimeSpanFormatter.TryFormatTimeAsString(locationToFormat.Start, out var startFormatted)) { childObjects.Add(new XAttribute("start", startFormatted)); } if (MinutesSecondsTimeSpanFormatter.TryFormatTimeAsString(locationToFormat.End, out var endFormatted)) { childObjects.Add(new XAttribute("end", endFormatted)); } if (!string.IsNullOrEmpty(locationToFormat.Description)) { childObjects.Add(new XAttribute("description", locationToFormat.Description)); } // extensions if (ExtensibleEntityFormatter.TryFormatXElementExtensions(locationToFormat, namespaceAliases, extensionManifestDirectory, out var extensionElements)) { childObjects.AddRange(extensionElements); } if (!childObjects.Any()) { return(false); } locationElement = new XElement(_media + "location", childObjects); return(true); }
private static bool TryParseMediaRssLocation(XElement locationElement, ExtensionManifestDirectory extensionManifestDirectory, out MediaRssLocation parsedLocation) { parsedLocation = default; if (locationElement == null) { return(false); } if (TryParseTimeSpanAttribute(locationElement.Attribute("start"), out var parsedStart)) { // ReSharper disable once ConstantNullCoalescingCondition parsedLocation = parsedLocation ?? new MediaRssLocation(); parsedLocation.Start = parsedStart; } if (TryParseTimeSpanAttribute(locationElement.Attribute("end"), out var parsedEnd)) { parsedLocation = parsedLocation ?? new MediaRssLocation(); parsedLocation.End = parsedEnd; } if (TryParseStringAttribute(locationElement.Attribute("description"), out var parsedDescription)) { parsedLocation = parsedLocation ?? new MediaRssLocation(); parsedLocation.Description = parsedDescription; } var emptyBeforeExtensions = parsedLocation == null; // extensions parsedLocation = parsedLocation ?? new MediaRssLocation(); ExtensibleEntityParser.ParseXElementExtensions(locationElement, extensionManifestDirectory, parsedLocation); if (emptyBeforeExtensions && !parsedLocation.Extensions.Any()) { return(false); } return(true); }