This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.Feeds/Structure/AtomCategory.cs

54 lines
1.3 KiB
C#

using System;
using System.Xml.Linq;
namespace MfGames.Nitride.Feeds.Structure;
/// <summary>
/// The type-safe structure for a entry's category element.
/// </summary>
[WithProperties]
public partial class AtomCategory
{
/// <summary>
/// Gets or sets the label associated with the category.
/// </summary>
public string? Label { get; set; }
/// <summary>
/// Gets or sets the scheme associated with the category.
/// </summary>
public Uri? Scheme { get; set; }
/// <summary>
/// Gets or sets the term of the category.
/// </summary>
public string? Term { get; set; }
/// <summary>
/// Creates an XML element out of the feed along with all items inside
/// the feed.
/// </summary>
/// <returns></returns>
public XElement ToXElement()
{
if (this.Term == null)
{
throw new NullReferenceException("Category term cannot be null.");
}
var elem = new XElement(XmlConstants.AtomNamespace + "category", new XAttribute("term", this.Term));
if (this.Scheme != null)
{
elem.Add(new XAttribute("scheme", this.Scheme.ToString()));
}
if (!string.IsNullOrEmpty(this.Label))
{
elem.Add(new XAttribute("label", this.Label));
}
return elem;
}
}