This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
PageRouteModel.cs
117 lines (104 loc) · 4.98 KB
/
PageRouteModel.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
namespace Microsoft.AspNetCore.Mvc.ApplicationModels
{
/// <summary>
/// A model component for routing RazorPages.
/// </summary>
public class PageRouteModel
{
/// <summary>
/// Initializes a new instance of <see cref="PageRouteModel"/>.
/// </summary>
/// <param name="relativePath">The application relative path of the page.</param>
/// <param name="viewEnginePath">The path relative to the base path for page discovery.</param>
public PageRouteModel(string relativePath, string viewEnginePath)
: this(relativePath, viewEnginePath, areaName: null)
{
}
/// <summary>
/// Initializes a new instance of <see cref="PageRouteModel"/>.
/// </summary>
/// <param name="relativePath">The application relative path of the page.</param>
/// <param name="viewEnginePath">The path relative to the base path for page discovery.</param>
/// <param name="areaName">The area name.</param>
public PageRouteModel(string relativePath, string viewEnginePath, string areaName)
{
RelativePath = relativePath ?? throw new ArgumentNullException(nameof(relativePath));
ViewEnginePath = viewEnginePath ?? throw new ArgumentNullException(nameof(viewEnginePath));
AreaName = areaName;
Properties = new Dictionary<object, object>();
Selectors = new List<SelectorModel>();
RouteValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// A copy constructor for <see cref="PageRouteModel"/>.
/// </summary>
/// <param name="other">The <see cref="PageRouteModel"/> to copy from.</param>
public PageRouteModel(PageRouteModel other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
RelativePath = other.RelativePath;
ViewEnginePath = other.ViewEnginePath;
AreaName = other.AreaName;
Properties = new Dictionary<object, object>(other.Properties);
Selectors = new List<SelectorModel>(other.Selectors.Select(m => new SelectorModel(m)));
RouteValues = new Dictionary<string, string>(other.RouteValues, StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Gets the application root relative path for the page.
/// </summary>
public string RelativePath { get; }
/// <summary>
/// Gets the path relative to the base path for page discovery.
/// <para>
/// This value is the path of the file without extension, relative to the pages root directory.
/// e.g. the <see cref="ViewEnginePath"/> for the file /Pages/Catalog/Antiques.cshtml is <c>/Catalog/Antiques</c>
/// </para>
/// <para>
/// In an area, this value is the path of the file without extension, relative to the pages root directory for the specified area.
/// e.g. the <see cref="ViewEnginePath"/> for the file Areas/Identity/Pages/Manage/Accounts.cshtml, is <c>/Manage/Accounts</c>.
/// </para>
/// </summary>
public string ViewEnginePath { get; }
/// <summary>
/// Gets the area name. Will be <c>null</c> for non-area pages.
/// </summary>
public string AreaName { get; }
/// <summary>
/// Stores arbitrary metadata properties associated with the <see cref="PageRouteModel"/>.
/// </summary>
public IDictionary<object, object> Properties { get; }
/// <summary>
/// Gets the <see cref="SelectorModel"/> instances.
/// </summary>
public IList<SelectorModel> Selectors { get; }
/// <summary>
/// Gets a collection of route values that must be present in the <see cref="RouteData.Values"/>
/// for the corresponding page to be selected.
/// </summary>
/// <remarks>
/// <para>
/// The value of <see cref="ViewEnginePath"/> is considered an implicit route value corresponding
/// to the key <c>page</c>.
/// </para>
/// <para>
/// The value of <see cref="AreaName"/> is considered an implicit route value corresponding
/// to the key <c>area</c> when <see cref="AreaName"/> is not <c>null</c>.
/// </para>
/// <para>
/// These entries will be implicitly added to <see cref="ActionDescriptor.RouteValues"/>
/// when the action descriptor is created, but will not be visible in <see cref="RouteValues"/>.
/// </para>
/// </remarks>
public IDictionary<string, string> RouteValues { get; }
}
}