File size: 5,038 Bytes
fab29d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;

namespace VersOne.Epub
{
    /// <summary>
    /// A single navigation element of the book (typically within the table of contents).
    /// Depending on the value of the <see cref="Type" /> property, it can act either as a header or as a navigation link.
    /// Unlike <see cref="EpubNavigationItem" />, this class contains the <see cref="HtmlContentFileRef" /> property
    /// which (if it's not <c>null</c>) holds only the reference to the file but doesn't have its content.
    /// </summary>
    public class EpubNavigationItemRef
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EpubNavigationItemRef" /> class with specified type, title, and nested items.
        /// </summary>
        /// <param name="type">The value determining whether this navigation item acts as a header or as a navigation link.</param>
        /// <param name="title">The title of the navigation element (which is either the text of the header or the title of the navigation link).</param>
        /// <param name="nestedItems">A list of child navigation elements constituting the nested navigational hierarchy within the navigation element.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="title" /> parameter is <c>null</c>.</exception>
        public EpubNavigationItemRef(EpubNavigationItemType type, string title, List<EpubNavigationItemRef>? nestedItems = null)
            : this(type, title, null, null, nestedItems)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EpubNavigationItemRef" /> class with specified type, title, link, HTML content file reference, and nested items.
        /// </summary>
        /// <param name="type">The value determining whether this navigation item acts as a header or as a navigation link.</param>
        /// <param name="title">The title of the navigation element (which is either the text of the header or the title of the navigation link).</param>
        /// <param name="link">The link of the navigation element if it acts as a navigation link or <c>null</c> if it acts as a header.</param>
        /// <param name="htmlContentFileRef">
        /// The EPUB content file reference for the navigation element or <c>null</c> if the value of the <paramref name="link" /> parameter is <c>null</c>.
        /// </param>
        /// <param name="nestedItems">A list of child navigation elements constituting the nested navigational hierarchy within the navigation element.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="title" /> parameter is <c>null</c>.</exception>
        public EpubNavigationItemRef(EpubNavigationItemType type, string title, EpubNavigationItemLink? link, EpubLocalTextContentFileRef? htmlContentFileRef,
            List<EpubNavigationItemRef>? nestedItems = null)
        {
            Type = type;
            Title = title ?? throw new ArgumentNullException(nameof(title));
            Link = link;
            HtmlContentFileRef = htmlContentFileRef;
            NestedItems = nestedItems ?? new List<EpubNavigationItemRef>();
        }

        /// <summary>
        /// Gets the value determining whether this navigation item acts as a header or as a navigation link.
        /// </summary>
        public EpubNavigationItemType Type { get;  }

        /// <summary>
        /// Gets the title of the navigation element (which is either the text of the header or the title of the navigation link).
        /// </summary>
        public string Title { get; }

        /// <summary>
        /// Gets the link of the navigation element if it acts as a navigation link or <c>null</c> if it acts as a header.
        /// </summary>
        public EpubNavigationItemLink? Link { get; }

        /// <summary>
        /// Gets the EPUB content file reference for the navigation element or <c>null</c> if the value of the <see cref="Link" /> property is <c>null</c>.
        /// </summary>
        public EpubLocalTextContentFileRef? HtmlContentFileRef { get; }

        /// <summary>
        /// <para>Gets a list of child navigation elements constituting the nested navigational hierarchy within the navigation element.</para>
        /// </summary>
        public List<EpubNavigationItemRef> NestedItems { get; }

        /// <summary>
        /// Returns a string containing the values of the <see cref="Type" /> and <see cref="Title" /> properties
        /// and the number of the elements in the <see cref="NestedItems" /> property for debugging purposes.
        /// </summary>
        /// <returns>
        /// A string containing the values of the <see cref="Type" /> and <see cref="Title" /> properties
        /// and the number of the elements in the <see cref="NestedItems" /> property.
        /// </returns>
        public override string ToString()
        {
            return $"Type: {Type}, Title: {Title}, NestedItems.Count: {NestedItems.Count}";
        }
    }
}