-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNavigationTopicViewModel.cs
72 lines (64 loc) · 4.11 KB
/
NavigationTopicViewModel.cs
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
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia
| Project Website
\=============================================================================================================================*/
using System.Collections.ObjectModel;
namespace OnTopic.ViewModels {
/*============================================================================================================================
| VIEW MODEL: NAVIGATION TOPIC
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a strongly-typed model for feeding views with information about a node in the navigation.
/// </summary>
/// <remarks>
/// <para>
/// No topics are expected to have a <c>Navigation</c> content type. Instead, this view model is expected to be manually
/// constructed by e.g. a <c>MenuViewComponent</c>.
/// </para>
/// <para>
/// Since .NET Standard doesn't support return-type covariance, this class can't be derived in a meaningful way (i.e., if
/// it were to be, the <see cref="NavigationTopicViewModel.Children"/> property would still return a <see cref="Collection
/// {T}"/> of <see cref="NavigationTopicViewModel"/> instances). Instead, the preferred way to extend the functionality is
/// to create a new implementation of <see cref="INavigationTopicViewModel{T}"/>. To help communicate this, the <see
/// cref="NavigationTopicViewModel"/> class is marked as <c>sealed</c>.
/// </para>
/// </remarks>
public sealed record NavigationTopicViewModel : INavigationTopicViewModel<NavigationTopicViewModel> {
/*==========================================================================================================================
| TITLE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <inheritdoc cref="TopicViewModel"/>
[Required]
public string Title { get; init; } = default!;
/*==========================================================================================================================
| SHORT TITLE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a short title to be used in the navigation, for cases where the normal title is too long.
/// </summary>
public string? ShortTitle { get; init; }
/*==========================================================================================================================
| WEB PATH
\-------------------------------------------------------------------------------------------------------------------------*/
/// <inheritdoc/>
[Required]
public string WebPath { get; init; } = default!;
/*==========================================================================================================================
| CHILDREN
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides a list of nested <see cref="NavigationTopicViewModel"/> objects, for handling hierarchical navigation.
/// </summary>
public Collection<NavigationTopicViewModel> Children { get; } = new();
/*==========================================================================================================================
| IS SELECTED?
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Determines whether or not the node represented by this <see cref="NavigationTopicViewModel"/> is currently selected,
/// typically meaning the user is on the page this object is pointing to.
/// </summary>
public bool IsSelected(string webPath) =>
$"{webPath}/".StartsWith($"{WebPath}", StringComparison.OrdinalIgnoreCase);
} //Class
} //Namespace