private static bool TryFormatMediaRssRestriction(MediaRssRestriction restrictionToFormat, out XElement restrictionElement) { restrictionElement = default; if (restrictionToFormat == null) { return(false); } restrictionElement = new XElement(_media + "restriction"); var valuesFormatted = string.Join(" ", restrictionToFormat.Values .Where(x => !string.IsNullOrEmpty(x)) .Select(x => x.Trim())); if (!string.IsNullOrEmpty(valuesFormatted)) { restrictionElement.Add(valuesFormatted); } if (restrictionToFormat.Relationship != null) { restrictionElement.Add(new XAttribute("relationship", restrictionToFormat.Relationship.Value.ToString().ToLowerInvariant())); } if (restrictionToFormat.Type != null) { restrictionElement.Add(new XAttribute("type", restrictionToFormat.Type.Value.ToString().ToLowerInvariant())); } return(true); }
private static bool TryParseMediaRssRestriction(XElement restrictionElement, out MediaRssRestriction parsedRestriction) { parsedRestriction = default; if (restrictionElement == null) { return(false); } var parsedValues = restrictionElement.Value .Trim() .Split(' ') .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => x.Trim()) .ToList(); parsedRestriction = new MediaRssRestriction { Values = parsedValues, }; if (TryParseEnumAttribute <MediaRssRestrictionRelationship>(restrictionElement.Attribute("relationship"), out var parsedRelationship)) { parsedRestriction.Relationship = parsedRelationship; } if (TryParseEnumAttribute <MediaRssRestrictionType>(restrictionElement.Attribute("type"), out var parsedType)) { parsedRestriction.Type = parsedType; } return(true); }