-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageProvider.cs
More file actions
57 lines (52 loc) · 1.5 KB
/
PageProvider.cs
File metadata and controls
57 lines (52 loc) · 1.5 KB
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
using System.Reflection;
namespace Modulight.Modules.Client.RazorComponents
{
/// <summary>
/// Specifies page provider.
/// </summary>
public interface IPageProvider
{
/// <summary>
/// Get module UI route root path, such as home, search, and so on.
/// Use <see cref="string.Empty"/> for no page module.
/// </summary>
string RootPath { get; }
/// <summary>
/// Check if a path is belongs to this module UI.
/// </summary>
/// <param name="path">Route path.</param>
/// <returns></returns>
bool Contains(string path);
}
/// <summary>
/// Default implement for <see cref="IPageProvider"/>.
/// </summary>
public abstract class PageProvider : IPageProvider
{
/// <summary>
///
/// </summary>
protected PageProvider()
{
RootPath = "";
var type = GetType();
{
var attr = type.GetCustomAttribute<ModulePageRootPathAttribute>();
if (attr is not null)
RootPath = attr.RootPath;
}
}
/// <inheritdoc/>
public string RootPath { get; protected set; }
/// <inheritdoc/>
public virtual bool Contains(string path)
{
if (RootPath is "")
{
return true;
}
path = path.Trim('/') + "/";
return path.StartsWith($"{RootPath}/");
}
}
}